'useSelector of React Redux don't update state of store on expo react-native

I made the same model on the web and it worked, I tried to use shallowEqual of Redux as second parameter of useSelector function, also the _.isEqual of lodash libary as there on the Redux documentation in Hooks section but don't worked.

Expected behavior:
On dispatch action the components with useSelector must bring the updated state.

What happens:
The components brings the initial state empity.

versions:

"Expo": "~37.0.3"
"react-native": "37.0.1",
"react-redux": "^7.2.0",
"redux": "^4.0.5"

EDITED:

I tried to reproduce the structure similar to the snack that also reproduced the same problem, here is the link: https://snack.expo.io/@danieltfischer/useselector



Solution 1:[1]

I have looked at your code, and I found one bug.

You are not exporting your action type string constant from the actions folder:

// What you are doing
const CREATE_MED = 'CREATE_MED';

// What you need to be doing
export const CREATE_MED = 'CREATE_MED';

After I fixed this, the app is working, as soon as I dispatch the action it brings back the latest state for me and updates the flatlist too.

Try making this change and see if it fixes it.

The reason it wasn't working is because every time the reducer function is called the CREATE_MED action constant is undefined, so it always went to the default options which was returning the previous state.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1