Easy-peasy: useStoreState doesn't react to changes in the state after Fast Refresh in React Native

Created on 18 Apr 2020  路  10Comments  路  Source: ctrlplusb/easy-peasy

Hi,

I added easy-peasy(v.3.3.0) successfully into a new React Native(v0.62.2) project but noticed that a function component using useStoreState will not react to the state after editing the component code. My button will send a request, receive a new picture of a dog and set that dog into the state but my component will not detect the state change. I have React Native's Fast Reload enabled.

Here is my test component (TestComponent.tsx):
````
import ...

export function TestComponent() {
const dog = useStoreState((state) => state.test.dog);
const getDog = useStoreActions((actions) => actions.test.getDog);

const handleGetDogPress = useCallback(async () => {
try {
await getDog();
} catch {
console.log('Simulated api error occurred');
}
}, [getDog]);

return (
{dog && }

needs-investigation

All 10 comments

Hi @shancial

Thanks for this report. I can empathise with that pain. I'll def make some time to look into this for you.

Thanks!

I can provide you with the test project code that I tested this with, but I basically used the official guide (npx react-native init AwesomeTSProject --template react-native-template-typescript) to set up a base and added easy-peasy with a property, setter and a thunk.

same issue.

It seems like Fast Refresh / react-refresh is also coming to create-react-app in the future.

Can also confirm this is happening to me as well. Anything I can do that would help with getting this looked into? :)

Hi all, I want to look into this. Are you all running the Expo CLI, and RN Web?

I am using the standard react-native CLI and React Native.

Are you all running the Expo CLI, and RN Web?

Next.js and CRA. Both are also facing this issue. You can find a small reproduction repo based on CRA here.

It's stripped down to only containing a counter and a button for incrementing the counter.

Changing the component makes the counter stop updating when clicking the button. According to the Redux DevTools the store state keeps updating on click.
Changing the component again without refreshing the page updates the counter once to the current store value, but the counter still does not update when clicking the button.

Changing the store logic (like changing the incrementing value) makes the refresh break completely. No changes on the component are reflected on the website anymore. Instead the counter keeps updating on every click, unfortunately it updates based on the old incrementing value.
I am not sure if that is the same issue or a different one, though.

I confirm the same as @rfermann issue is happening with nextjs.

I just ran into this too building an app that uses Fast Refresh, but for the web, and not with React Native.

Edit: After an HMR update, the actions are definitely continue to fire based on adding console.debug statements to the function.

It seems like the type of state update may be involved. If I push onto an array even after a hot update, the state continues to update fine and components on screen will refresh as expected. However, if I modify the array with a splice to delete an item, then the components do not refresh (yet the change is applied to the state because I am using localStorage persistence).

Edit 2: I also see that performing an behavior (i.e. button click) which modifies local state with a useState() hook causes all components to refresh once (including those using state from EP), but the action handlers that delete an item with a .splice() continue to not trigger a refresh. Very odd.

Was this page helpful?
0 / 5 - 0 ratings