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.

Migrating from Context (questions)

See original GitHub issue

Zustand looks amazing but I need some help figuring out how to migrate from Context to Zustand in my hobby project. I have Auth & User Provider via Context right now. How would I best switch from Context to Zustand? I’m using React Native.

<AuthProvider>
        <UserProvider>
              <BottomTabProvider>{children}</BottomTabProvider>
        </UserProvider>
</AuthProvider>

UserProvider has a useEffect for making a API request to download user object if Auth is true;

useEffect(() => {
    const getUser = async () => {
      try {
        const res = await axios.get(url, {
          withCredentials: true,
        });
        setUser({
          firstName: res.data.name.first,
        });
        setLoading(false);
      } catch (err) {}
    };
    if (auth) {
      getUser();
    }
  }, [auth, url]);

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
dai-shicommented, Nov 12, 2020

Still not confident if I get it, but the store value can be updated anywhere (except for the render body), and the hook will be properly notified the changes.

0reactions
dai-shicommented, Dec 13, 2020

Assuming this is resolved, let me close this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

From Redux to the Context API: A Practical Migration Guide
Let's migrate a React application built with Redux to the Context API and see how it looks like. ... Here are some helpful...
Read more >
Migrate from context to Redux - Stack Overflow
Is it a good idea to migrate piece by piece and have both Redux and Context in the same app until I migrated...
Read more >
Migrating to React's New Context API - Kent C. Dodds
As I've been working on updating the course, I've been migrating from the old context API to the new one and I thought...
Read more >
Migrating Classic Quizzes and Question Banks to ... - YouTube
0:00 Introduction1:19 Migrating quizzes3:08 Migrating question banks to item banks.
Read more >
50 Data Migration Interview Questions and Answers - YouTube
Dear Friends,A warm welcome to this rare set of 50 Data Migration interview questions.For the basics of Data Migration, Migration Testing ...
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