Good pattern for updating atoms based on subscription
See original GitHub issueLets say I have an API that I can subscribe to, and any time a value changes (can happen once a frame at 60FPS) I would want to update an atom to always reflect that
Currently I can just create a useEffect to do this at the App.tsx level, but wondering if there’s an atoms-only way to do this.
some pseudocode:
useEffect(() => {
async function load() {
setAtom(client.get(someId))
}
client.subscribe(someId, (msg) => setAtom(msg));
() => {
client.unsubscribe(someId);
}
}, [])
Issue Analytics
- State:
- Created 3 years ago
- Comments:23 (18 by maintainers)
Top Results From Across the Web
How To Make And Maintain Atomic Design Systems With ...
This article provides a detailed guide to building and maintaining atomic design systems with Pattern Lab 2. The benefits of UI design systems ......
Read more >How to organize your components using the Atomic Design
First of all we have to create our folder structure in which store our components. So, let's create a src directory which will...
Read more >Publisher Subscriber (Pub-Sub) Design Pattern
The publish subscribe pattern, sometimes known as pub sub pattern, is an architectural design pattern that enables publishers and subscribers to communicate ...
Read more >Jotai: The Ultimate React State Management - 100ms
Jotai, the atom-based state management for React. But what is Jotai, ... Jotai is based on the new Recoil pattern and library by...
Read more >An Introduction to Atomic Design and Pattern Lab in SiteFarm
complete: pattern is ready to be moved to production. a green dot. Pattern State Example. This is great when developing for a client...
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
atomWithObservable
with initial value to avoid suspense? That’s possible. We did something like that inatomWithQuery
injotai/query
. Would you like to open a new issue for tracking?For this specific purpose, we have
loadable
.Let me try ideating something.
So, what works now is something like this:
Let’s see if we can generalize a bit.
Just a rough idea.