我正在使用react-native@0.60.5
和react-native-router-flux@4.0.6
。我正在尝试从selectItems
组件跳回到newCollection
,这是一种形式。
我创建了一个组件,该组件呈现带有复选框的项目列表。当用户点击 Done (完成)按钮时,我使用setParams
将选定的项目作为道具传递-就像这样:
// SelectItems.js
this.props.navigation.setParams({
rightTitle: 'Done',onRight: () =>
actions.jump('newCollection',{
selectedItems: this.state.taggedItems,}),});
这很好,并且当newCollection
组件呈现时,我可以在表单中显示this.props.selectedItems
中的选定项目列表。
安装组件时,我需要使用this.props.selectedItems
来调用动作创建者。
这是动作:
// NewCollection.js
// Map the items selected in the the `selectItems` component
// and invoke an action
var fetchTaggedItems = new Promise((resolve,reject) => {
this.props.taggedItemsFetch(this.props.taggedItems.map(x => x.uid));
resolve(this.props.matchingOutfits);
});
fetchTaggedItems.then(x => {
console.log(x);
alert('done!');
});
现在,我的理解是,组件在收到这些新道具时应该重新安装,但事实并非如此。使用componentDidmount
中的日志,我看到它仅安装在第一个条目上。
我尝试了上面的代码:
- 使用
actions.refresh()
代替actions.jump()
-什么也没发生 - 使用
static onEnter()
更新组件状态并强制重新安装-无法访问this.state
- 从
render()
-无限循环中调用动作创建者 - 在状态中设置布尔值
calledactionCreator
来防止无限循环-不起作用 —将this.props
中的prevProps
与componentDidUpdate()
比较—错误:超出最大更新深度
我开始认为这是React Native Router Flux的错误。