Description
Do you want to request a feature or report a bug?
Report a bug.
What is the current behavior?
I'v created a reproducing repo here https://github.com/malash/react-redux-issue-ref/blob/master/reduxBug.js
This repo use both react-redux
and react-native
.
<Button
title="[BUG] Click Me (setTimeout)"
onPress={() => {
setTimeout(() => {
dispatch({type: 'NOOP'});
dispatch({type: 'TOGGLE'});
}, 0);
}}
/>
When using setTimeout
's callback to dispatch multi times, the useSelector
return incorrect value. The reason why I use setTimeout
is to ensure these dispatch calling are non-batched.
const selector = state => ({
bool: state.bool,
});
const ReduxBugParent = () => {
const {bool} = useSelector(selector);
// ...
<Text>bool from useSelector is {JSON.stringify(bool)}</Text>
<Text>bool from store.getState is {JSON.stringify(boolFromStore)}</Text>
}
After click the button different selector result are shown. the bool
are always different with boolFromStore
.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to a CodeSandbox (https://codesandbox.io/s/new) or RN Snack (https://snack.expo.io/) example below:
- Clone the repo https://github.com/malash/react-redux-issue-ref
- Install React Native CLI
- Run
react-native run-ios
- Click buttons and see rendered values.
What is the expected behavior?
This bug can only reproduce on non-web environment, maybe it is related to #1436
I believe it should works on React Native as well as React DOM.
Which versions of React, ReactDOM/React Native, Redux, and React Redux are you using? Which browser and OS are affected by this issue? Did this work in previous versions of React Redux?
react@16.9.0
react-native@0.61.2
react-redux@7.1.1
redux@4.0.4
cc