我正在使用几个还原器(通过combineReducers() )进行项目。
我有一个组件,它不分发任何操作,只显示来自redux状态的信息。它通过connect函数连接到此状态:
class MyComponent extends React.Component {
componentWillMount() {
// some code
}
render() {
return(
<Text>
{ this.props.value }
</Text>
)
}
}
function mapStateToProps(state) {
return {
value: state.updaterReducer.value,
}
}
export default connect(
mapStateToProps,
) (MyComponent);该项目中还有另一个部分/组件,它更改redux状态和值:
import { makeUpdate } from './updater.actions.js';
import configureStore from '@redux/configureStore.js';
const store = configureStore();
// This function is can be called by some buttons in the app:
export default function update() {
console.log('Update function called');
store.dispatch(makeUpdate());
}这是我的问题:当调用update时,更新程序动作和更新器还原器都被调用,这样redux状态就会发生变化,但是'MyComponent‘永远不会更新。
发布于 2018-08-02 08:20:27
我可以自己解决这个问题:最终解决方案非常容易,但是无法根据最初问题中的代码找到:每次我需要redux商店时,我都使用一个来自网络教程的配置存储函数来创建它。因此,我创建了多次“同一”商店。不幸的是,这些商店之间没有联系.
有时这在项目中有效,因为mapStateToProps--函数和mapDispatchToProps--函数都位于同一个组件中,并且使用one存储,但有时(如问题中的例子),这些函数使用不同的存储,不能相互影响。
https://stackoverflow.com/questions/51633258
复制相似问题