【发布时间】:2019-11-11 19:01:01
【问题描述】:
我正在使用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与componentDidUpdate()中的prevProps进行比较 — 错误:超出最大更新深度
我开始认为这是 React Native Router Flux 的一个错误。
【问题讨论】:
-
请也提供有关您的其他组件的更多信息
-
我添加了代码来展示我如何调用动作创建者。还有什么有用的吗?
标签: javascript reactjs react-native react-redux react-native-router-flux