私はReactを初めて使用しています。これはおそらくノブの質問です。子供の小道具を変更するには?
ユーザーがチェックボックスをクリックすると、MeteorGriddleコンポーネントの "filteredFields"小道具を変更したいと思います。私のJSX:
const bookingsPage =() => {
let filteredFields = ['userName'];
const handleClick = (e) => {
if (e.target.checked) {
filteredFields = ['userEmail'];
// How to propagate this change to the MeteorGriddle?
}
}
return (
<div>
<label><input type="checkbox" defaultChecked="true" value="userEmail" onClick={handleClick}/>Email</label>
<MeteorGriddle filteredFields={filteredFields}/>
</div>
);
};
、以下のコードのように試すことができます代わりに 'props'を変更します。代わりに' states'を使います –
あなたの場合は、ステートレスコンポーネントではできません。ステートを持つ通常のコンポーネントを作成し、ハンドラの 'this.setState'で状態をシャットダウンし、' MeteorGriddle'にparamとして渡します – Maxx