2016-12-15 8 views
3

JSXを私の還元状態、つまりグローバルに使用されるモーダルコンポーネントに対してどのように渡すかを調べるのに問題があります。その1つのパラメータがcontentの場合は還元状態です。 JSXコードを含むように更新されました。次のエラーの多いjsxコンテンツを還元状態にしてそこからレンダリングする

invariant.js:38 Uncaught Error: Objects are not valid as a React child (found: object with keys {dispatchConfig, _targetInst, isDefaultPrevented, isPropagationStopped, _dispatchListeners, _dispatchInstances, nativeEvent, type, target, currentTarget, eventPhase, bubbles, cancelable, timeStamp, defaultPrevented, isTrusted, view, detail, screenX, screenY, clientX, clientY, ctrlKey, shiftKey, altKey, metaKey, getModifierState, button, buttons, relatedTarget, pageX, pageY}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of styled.div .

::私はしかし、関数が正しく呼び出されて、私はまた、次のエラーを取得していますように見えていません、それは正しいコンテンツをレンダリングするために取得しています現時点では

warning.js:36 Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property nativeEvent on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist(). See https://fbme(replaced this as so doesn't allow links to fb)/react-event-pooling for more information.

の実装例:モーダルを表示すると続きを追加するページから呼び出さ

機能

export const modalToggle = (content = '') => ({ 
    type: MODAL_TOGGLE, 
    payload: content 
}); 

私はその後、私のモーダルコンテナ内で、このようなコンテンツをレンダリングしよう:

return (
<div>{this.props.content}</div> 
) 

私は私にReactを輸入し、それ

this.props.modalToggleはこのようなReduxのアクションです
onToggleModal =() => { 
    this.props.modalToggle(
     (<TopUp account={getSession().accounts[0] || {}} />) 
    ); 
    } 

にエントJsxの問題を解決することを望んでいたが、運がなかった。それはコンポーネントが奇妙なオブジェクトのいくつかの並べ替えのような減速機に渡されるようにも思える。

+0

あなたはモーダルと 'redux'パターンを探しているなら、私は非常にこのアプローチを提案します。http://stackoverflow.com/questions/35623656/how-can-i-display-a-mode-dialog-in-redux-that-performing-asynchronous-actions私たちは現在プロダクションでそれを使用しており、非常に安定しています。 – lux

+0

@luxはうまく見えますが、私は小道具として機能を渡すのが難しいです。 – Ilja

答えて

1

Redux状態には単純なオブジェクトとデータ型しか含まれないため、JSXオブジェクトによって問題が発生する可能性があります。また、あなたの状態の一部としてJSXオブジェクト(基本的にはビューです)を持たせるのは良い考えではありません。

代わりに、最終ビューのレンダリングに必要なすべてのデータを渡す必要があります。私はこれが仕事だと思う:

onToggleModal =() => { 
    this.props.modalToggle(getSession().accounts[0] || {}); 
} 

export const modalToggle = (account = {}) => ({ 
    type: MODAL_TOGGLE, 
    account: account 
}); 

​​
+1

しかし、他のモーダルビューでは必ずしも同じではない異なるコンポーネントをモーダルで表示する必要がある、より複雑な例があります。私はこれを行うために考えることができる唯一の方法は、これらのビューのすべてをModalコンテナで事前定義し、あなたが示唆したようなredux経由でデータを渡し、どのようなビューをレンダリングするかを示すTYPEパラメータを実行することができます非常にコードの重い実装のように、ここでこの質問をします。より良い答えがポップアップしなければ、私はそれに付随しなければならないと思う。 – Ilja

関連する問題