react-redux 6 + React Native - not firing mapStateToProps after state changes
See original GitHub issueWhat is the current behavior?
mapStateToProps
is run once when the component loads, but does not run again when state is changed.
Given a component of
export default ({
testx,
}) => (
<View>
<Button title="Load" onPress={() => dispatchTest()} />
<Text>{testx}</Text>
</View>
);
A mapStateToProps
of
const mapStateToProps = state => ({
testx: state.test,
});
A mapDispatchToProps
of
const mapDispatchToProps = {
dispatchTest: test,
};
An action creator of
export const TEST = 'TEST';
export const test = () => ({
type: TEST,
});
And a reducer of
export default (state = initialState, action) => {
switch (action.type) {
case TEST:
return { ...state, test: 'toast' };
default:
return state;
}
};
Logging confirms that the state is being updated but that mapStateToProps is not being rerun afterwards. The component will continue to display the initial value of test
and will never display the new value set in state by the reducer (toast
).
What is the expected behavior?
The state change made by the reducer ought to cause redux to rerun mapStateToProps, thereby updating the props received by the component.
Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?
This issue is happening since I updated react-redux from 5.1.1 to 6.0.0. Downgrading react-redux back to 5.1.1 fixes the problem and everything behaves as expected. I am using React 16.6.3 and React Native 0.57.1.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:31 (9 by maintainers)
Top GitHub Comments
i am still facing this issue , anybody plz help me. mapStateToProp function not getting executed.
my project has these dependencies
“expo”: “^32.0.0”, “react”: “16.5.0”, “react-native”: “https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz”, “react-native-elements”: “^1.0.0-beta7”, “react-native-maps”: “^0.22.1”, “react-native-status-bar-height”: “^2.2.0”, “react-native-typography”: “^1.4.0”, “react-native-vector-icons”: “^6.1.0”, “react-navigation”: “^3.3.2”, “react-redux”: “^6.0.1”, “redux”: “^4.0.1”, “redux-thunk”: “^2.3.0”
any one plz help me
Hey guys! For anyone who will faced with issue. I can confirm, for me this problem solved by downgrading from (react: ‘16.8.9’):
`“dependencies”: {
},`
To (react: ‘16.5.0’):
`“dependencies”: {
},`
Thanks.