Reputation: 1
I am currently working on an React-Application where I use Immutable.js in my Redux-Reducers. The reducers will return the previous state as a reference if they have not changed it (as recommended).
If I now compared the previous state with the next state (state===nextState)
it would return true, since the reference has not changed, right?
Now if the reducer changed the state, it would return a new Immutable.js Map.
Doing the same comparision now it would return false, since it is a new Map.
Would it be reasonable to somehow detect prop changes within shouldComponentUpdate like that?
If so, is there a way to modify the react-redux connect function to use my custom shouldComponentUpdate method? Because apparently it is not possible to pass an Immutable.js Object as props to a component.
Upvotes: 0
Views: 70
Reputation: 33
In mapStateToProps, if you are not converting this immutable iterable to equivalent JS object and pass Immutable object as it is. You can do achieve it.
For example:
Instead of
const mapStateToProps = (state) => ({ ...(state.toJS()) });
Way to access any data from state in the component: this.props.data
You can also write as:
const mapStateToProps = (state) => ({ state });
Way to access any data from state in the component: this.props.state.get('data')
Upvotes: 1