[ Question ] How to make a store instance per Component ?
See original GitHub issuelet’s say you have a <Button />
component which some how stores it’s state in zustand
with buttonStore
store.
now you want each button to have it’s own state / store ( zustand store/state )
how would you achieve that ?
Issue Analytics
- State:
- Created 3 years ago
- Comments:22 (9 by maintainers)
Top Results From Across the Web
[ Question ] How to make a store instance per Component
One use case is that we want to create a store in React tree, and then pass it with props or context. This...
Read more >How to create one store per instance in Redux? - Stack Overflow
I wonder how to dispatch actions to the component's own special store? Is there a way to access the store -prop of the...
Read more >React Components, Elements, and Instances – React Blog
We let React create, update, and destroy instances. We describe them with elements we return from the components, and React takes care of ......
Read more >How To Create Custom Components in React - DigitalOcean
In this tutorial, you'll learn to create custom components in React. Components are independent pieces of functionality that you can reuse ...
Read more >How get lightning-tree to render separate component instance ...
TLDR - iterate instances that I wanna render and dynamically update their visibility. Keep cache of already rendered components and use css ...
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
it’s not 100% clear to me what you mean, but the store can be created everywhere, it doesnt violate rules of hooks because it is not a hook, it merely returns one.
it’s just that it’s now being the users responsibility to distribute it, because its not a global singleton any longer but has a lifecycle. this is where context is probably best. but you could also do prop drilling if you wanted.
store.js
now every component inside Store can use the hook.
app.js
foo.js
and just like that we have a dynamic, component bound store that is lifecycle-safe. i guess we have re-created react-redux with the provider and all 😛
Funny thing -> I was using react context providers and then was context bridging to work with react-three-fiber. Then I moved everything off from context and moved to zustand. Life was good. Now I need multiple instances of my 3d component. So I need to provide the zustand store I create via contextproviders bridged between three-fiber’s canvas and normal react-dom. Thumbsup if you’re all coming full circle like me 👯
PS: I still love this library. You guys are great.