feature request: option for useStore.subscribe fire once on initialisation
See original GitHub issueCurrently useStore.subscribe
only fires when the subscribed part of the store changes. It would be useful if there was an option to force the function to fire once upon initialisation. Maybe I’m missing something, here’s an example:
useEffect(() => {
// I don't want to have to repeat myself up here just for initialisation
const { position, rotation } = getSceneObject(props.id)(useStore.getState())
target.current.position.set(position[0], position[1] - 3, position[2])
plane.current.position.set(...position)
plane.current.rotation.set(rotation[0], Math.PI, 0)
return useStore.subscribe(
({ position, rotation }: SceneObject) => {
target.current.position.set(position[0], position[1] - 3, position[2])
plane.current.position.set(...position)
plane.current.rotation.set(rotation[0], Math.PI, 0)
},
(state) => getSceneObject(props.id)(state)
)
}, [props.id])
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:15 (10 by maintainers)
Top Results From Across the Web
Recipes - Zustand Documentation - Pmndrs.docs
For more control over re-rendering, you may provide an alternative equality ... fires on every change const unsub1 = useStore.subscribe(console.log) ...
Read more >Subscribe fires twice when I revisit a page - angular
When you revisit it will create an instance of that service and initialize all the subscription once again because you have injected via ......
Read more >Zustand | The State of State Management in React - Morioh
It may be the one state-manager in the React space that gets all of these right. ... fire immediately const unsub5 = useStore.subscribe(state...
Read more >QRadar APARs 101 - IBM
The hostcontext service fails to initialize after the appliance reboot. ... optimize option can be required for proper QRadar performance and functionality.
Read more >Hooks API Reference - React
They let you use state and other React features without writing a class. ... The default behavior for effects is to fire the...
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
Just dropping in my 2c here to think about for potential future dev: I use this feature all the time in MobX. They have optional params you can pass into the subscribe function, one is called
fireImmediately
, which does exactly what it sounds like.I will try this feature (
fireImmediately
option) along with #555. It will be a new middleware.