Reputation: 2384
Inside react-relay app I need to change my sidenav component based on state of main content component.
Is it any simple global store for client component communication? Would it be ok to use dummy mutation and bounce back or should I keep my state in least common parent?
Upvotes: 0
Views: 126
Reputation: 1193
If you use Redux you can connect your App with the global state. Then both your components can be set-up by passing the same prop to them.
Let say you define your App. In render you should have something like:
render() {
const {myValue} = this.props;
return (<div>
<MyFirstComponent propValue={myValue}/>
<MySecondComponent propValue={myValue}/>
</div>
);
}
Then at the end of the App
App.propTypes = {
myValue: PropTypes.object
};
function mapStateToProps(state) {
return {
myValue: state.myReducer.myValue
}
}
export default connect(mapStateToProps)(App)
Everytime you dispatch an action which will return an updated value of myValue both the components will be sharing it.
Upvotes: 1