我可以在将它们分开的同时使用反应导航和 redux 吗?
can I use react navigation and redux while keeping them separated?
我正在尝试编写一个同时使用 redux 和 react native 导航的 react native 应用程序。但是,我实际上并不想在 redux 中保存我的导航状态。所以我只想让他们彼此分开。我目前有 StackNavigator,它被包裹在一个连接中,然后由提供者包裹。
const mapStateToProps = state => state;
const mapDispatchToProps = dispatch => dispatch;
// need this Higher Order Component so you can pass properties through the root stack
const AppContainer = connect(mapStateToProps, mapDispatchToProps)(RootStack);
export default class App extends Component {
render() {
return (
<Provider store={Store}>
<AppContainer />
</Provider>
);
}
}
这个实现可行吗?
是的,这是可能的,事实上,鼓励。
来自 react-navigation 文档的引述:
Some folks like to have their navigation state stored in the same place as the rest of their application state. Think twice before you consider doing this, there is an incredibly good chance that you do not need to do this!. Storing your React Navigation state in your own Redux store is likely to give you a very difficult time if you don't know what you're doing.
默认情况下,Redux 和 React-Navigation 彼此无关,在其下一个版本(2018 年秋季)中,将不会记录或鼓励将 React-Navigation 集成到您的 redux 状态中。
我正在尝试编写一个同时使用 redux 和 react native 导航的 react native 应用程序。但是,我实际上并不想在 redux 中保存我的导航状态。所以我只想让他们彼此分开。我目前有 StackNavigator,它被包裹在一个连接中,然后由提供者包裹。
const mapStateToProps = state => state;
const mapDispatchToProps = dispatch => dispatch;
// need this Higher Order Component so you can pass properties through the root stack
const AppContainer = connect(mapStateToProps, mapDispatchToProps)(RootStack);
export default class App extends Component {
render() {
return (
<Provider store={Store}>
<AppContainer />
</Provider>
);
}
}
这个实现可行吗?
是的,这是可能的,事实上,鼓励。
来自 react-navigation 文档的引述:
Some folks like to have their navigation state stored in the same place as the rest of their application state. Think twice before you consider doing this, there is an incredibly good chance that you do not need to do this!. Storing your React Navigation state in your own Redux store is likely to give you a very difficult time if you don't know what you're doing.
默认情况下,Redux 和 React-Navigation 彼此无关,在其下一个版本(2018 年秋季)中,将不会记录或鼓励将 React-Navigation 集成到您的 redux 状态中。