question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Native fast refresh problems

See original GitHub issue

Hi !

I’m using Zustand v3 with React Native and everything works great. Troubles comes when I hit save and app is fast-refreshed: my store is emptied and no update is trigger anymore after that. The only way to make this work again is to reload the whole app. This weird behavior appears only when I hit save on my useStore file (which create store with create())

I’m doing something like this:

// App.js
const App = () => {
  const getLists = useStore((state) => state.getLists);
  const lists = useStore((state) => state.lists);
  useEffect(() => {
    getLists();
  }, []);
 
  console.log(lists);
  ...
}

the getLists method:

  // useStore.js
  getLists: async () => {
      const lists = await getLists();
      set({ lists });
  },

the addList method:

  // useStore.js
  addList: (list) => {
      const lists = [...get().lists];
      lists.push(list);
      set({ lists });
  },

So if I save my useStore.js, fast refresh comes in, and then if I try to add with my addList method, console.log is not called because the component is not rendered any more (but I think it should because I updated lists). I confirm that this experiment works when I’m not using fast refresh of when I’m not saving useStore.js (console log is called so App is re-rendered).

Let me know if you need more information or a RN repo to reproduce this !

Thanks for this nice library btw 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
dai-shicommented, Oct 20, 2020

Yeah, let’s leave it open for a while. Thanks for your reporting anyway!

2reactions
thomasgossecommented, Oct 21, 2020

I created a repo with the weird behavior: https://github.com/thomasgosse/RNFastRefreshZustand

You can try it both on iOS and Android. I put instructions on src/components/hooks/useTheme.js Keep in mind that this happen only when you hit save on the src/components/store/useStore.js file !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fast refresh not working in React Native 0.64.2 #32001 - GitHub
I was seeing fast refresh not working when going from react-native 0.63.3 to 0.64.0. Turned out the issue was 0.63.3 used to have...
Read more >
React-native Fast Refresh broken - Stack Overflow
I have to stop and uninstall the app, run npm run -- --reset-cache and then run npm run android again in order to...
Read more >
Fast Refresh - React Native
Fast Refresh is a React Native feature that allows you to get near-instant feedback for changes in your React components. Fast Refresh is ......
Read more >
What are some features of Fast Refresh in React native
Fast Refresh cannot change the React local state in function components and Hooks. It avoids reloading the app. You can change state forcefully....
Read more >
New Fast Refresh Feature in React Native 0.61
These were very useful features while debugging your app as it reloads your app nearly in runtime and you can see the changes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found