我在一個陣營項目中,用戶將被提示一系列問題的工作,這些問題的答案將被合併爲對象進行保存。如何在使用react-router時從子組件設置父組件的狀態?
父組件包含幾個孩子。
爲example--
<Route path="Parent" component={Parent}>
<Route path="Child1" component={Child1} />
<Route path="Child2" component={Child2} />
<Route path="Child3" component={Child3} />
<IndexRoute component={Child1} />
</Route>
父將具有空值 前的初始狀態。 (this.state = {value1:「」,value2:「」})
使用{this.props.children時,如何將數據從孩子傳遞給父母(以及從父母到孩子的道具) }?
太好了。請考慮不要使用'state'並將實現移到''''''''''''''''''''''如' – Hitmands
對於反應路由器v4,這是一個首選的方式,只要確保使用渲染而不是組件來避免額外的安裝和重新渲染。 –
正是我在找的,謝謝! –