私は古いReact.createComponent
のプロジェクトを新しいES6クラス定義に変換しています。React - JSXコンポーネントの配列を作成するときにオブジェクトがリアクションの子として有効でない
class AnswerFrame extends React.Component {
constructor(props) {
super(props);
}
render() {
var props = this.props;
var selectedNumbers = props.selectedNumbers.map(function (i) {
return (
<span onClick={props.unselectNumber.bind(null, i)}>
{i}
</span>
)
});
return (
<div id="answer-frame">
<div className="well">
{selectedNumbers}
</div>
</div>
);
}
};
アイデアは、それぞれのonclickイベントを有するスパンの配列である配列、selectedNumbers
を定義することである:私は、次の成分を有します。これらはレンダリングされます。
このコードはES6に変換する前にうまく働いたが、今私に次のエラー与えている:これはもう機能していないのはなぜ
Error: Objects are not valid as a React child
(found: object with keys {dispatchConfig, _targetInst, 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, isDefaultPrevented, isPropagationStopped, _dispatchListeners, _dispatchInstances}).
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 `AnswerFrame`.
を?
その配列には 'numbe r/string'または 'オブジェクトの配列'? 'console.log(this.props.selectedNumbers)'の結果を表示できますか? –
このメッセージは 'this.props.selectedNumbers'の内容に関するものだと思います。数字があると確信していますか? –
スパン要素に 'key'プロパティがないとこの問題が発生するのでしょうか? –