Pass initial state to useReducer
See original GitHub issueFirst and foremost, awesome idea with using Proxy
to track conditional component updates.
How would I go about passing a dynamic initial state into useReducer
? Something like the following:
const useValue = value => useReducer(store.reducer, value);
export function StoreProvider({ value, children }) {
return <Provider useValue={() => useValue(value)}>{children}</Provider>;
}
In the above case I get:
useValue must be statically defined
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
React useReducer Hook ultimate guide - LogRocket Blog
Specifying the initial state ... If you don't pass a third argument to useReducer , it will take the second argument as the...
Read more >how to set the initialState with useReducer React
You can just call the searchUsers() function in useEffect() to get some users and set the state. if you want to get initial...
Read more >An Easy Guide to React useReducer() Hook - Dmitri Pavlutin
The useReducer(reducer, initialState) hook accept 2 arguments: ... Start, Stop and Reset, and has a number displaying the passed seconds.
Read more >3 Managing component state with the useReducer hook
The component passes the initial state and the reducer to the useReducer function. React sets the current state for the reducer as the...
Read more >How to use React useReducer hook like a pro - Devtrium
The first is the state , and the second is a function that lets you modify the state: setState for useState , and...
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 FreeTop 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
Top GitHub Comments
My bad. It should be:
Thanks. I will file a new issue.