How to use multiple hooks that depend on each other?
See original GitHub issueExample:
const [authUser, authLoading, authError] = useAuthState(firebase.auth());
const [user, userLoading, userError] = useDocument(firebase.firestore().doc(`users/${authUser.uid}`));
I can’t put useDocument
in a if (authUser)
because React breaks with: Rendered more hooks than during the previous render.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
React hooks and their dependence on each other
You can add more states and effects to this components and chain them using this method so they don't clash with each other....
Read more >Rules of Hooks - React
They let you use state and other React features without writing a class. Hooks are JavaScript functions, but you need to follow two...
Read more >React component with two dependent useEffect hooks
externalRequest(0, newFilters). What I'd consider to be a workaround is either to store the page as a mutable reference as follows:
Read more >React hooks... Oops! Part 2 - why does my effect run multiple ...
fn is the effectful function, and deps is an array of values it depends on. Every time the component renders, React checks if...
Read more >React hooks: how to use useState and useReducer effectively?
In this article we will discover two hooks, the basic one useState, ... all begin with a three-letter 'use', but with different functionality...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
this is the pattern i use a lot, in a hook called
useUser
so I don’t duplicate it as much, basically looks like thisi dont think
useDocumentData(auth && firebase.firestore()...)
usage is correctI saw that, but I guess I’m kind of confused. What I have now is similar to that, I think? But I get:
Warning: Cannot update during an existing state transition (such as within
render). Render methods should be a pure function of props and state.