Comments (5)
This is great! It would be good to test the performance when React is not in development mode. I was seeing comparable speeds with the production version of React.
But this is definitely worth exploring. I was just prototyping something that involved updating the store without calling React's dispatch
(not performance related). It seems like we should enable full features for reading and writing state outside of React. We might need to make some of the types less strict. I'll look into this today.
from zustand.
It's difficult to define the function signature of StateListener. Apparently generics are inferred as {}
if used before being assigned a type. StateSelector is the second argument so the generic U
is not inferred yet when the StateListener type is defined. I was able to get it to work by reversing the parameter order: subscribe(selector | listener, listener)
but I don't like it.
from zustand.
you mean i could either do
sub(state => console.log("state changed"))
or
sub(state => state.x, x => console.log("x has changed"))
?
I would actually prefer this : D but probably only because i don't know TS good enough to see the downsides (?)
from zustand.
Yes, you would be able to do that. The selector function is optional and I'm used to optional parameters being last. Haha I guess it's mostly preference though. If you like it, I'm fine with it.
from zustand.
Wound you merge it? I think this functionality would make it very versatile.
from zustand.
Related Issues (20)
- devtools.d.ts node_modules/zustand/middleware/devtools.d.ts:33:42 - error TS2312: An interface can only extend an object type or intersection of object types with statically known members. HOT 2
- When the set operation is executed in the 「then callback」, the 「set operation」 takes nearly a hundred times longer.
- Resetting Multiple Stores Example Doesn't Work with the Currying Required Elsewhere for Typescript Support
- 123e
- In nextjs13's app directory, how can the server components send Fetch?
- Unnecessary Renders Triggered by a Hook after Migrating to Zustand
- with immer midderware, Array type wrong HOT 2
- The reactNode is stored in the store, sometimes causing the component to lose update. HOT 1
- Is there a way to reset data when switching routes? The previous method cannot take effect#1192
- Type problem with persist HOT 3
- Reset store not working on log out
- I can't update state with new data from Tanstack Query HOT 2
- The app hanging when initializing the store with and array of objects. HOT 4
- Is there any chance to simplify types?
- How to move the router state to store?
- Website graphics rendering issues (Linux) HOT 3
- shallow not support nested object HOT 1
- Are these two methods exactly the same? HOT 1
- It’s not recommended to suspend a render based on a store value returned by useSyncExternalStore.
- RFC: How is v5-alpha? HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zustand.