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)
- The value I save to storage with persist is delayed when the page refreshes.
- State updated in one component but not in another one
- Typescript + Slices = trouble HOT 7
- Setting nested state make the other states change (their values didn't change)
- zustand concurrent update issue
- Typo in GitHub "About" HOT 1
- import { create ,WritableDraft} from "zustand" HOT 1
- Introduction Zustand page a documentation typo HOT 1
- Ts error on type annotation HOT 3
- Persist middleware keeping old versions of functions around. Breaking apps when deploying to prod
- devtools with option `serialize.immutable` does not deserialize state from devtools correctly (broken redux devtools "Jump" / "Revert" etc.)
- state empty on first render HOT 1
- onRehydrateStorage is invoked before storeage.getItem HOT 1
- About API
- About api docs
- Documentation incorrect: Usage with React Contexts HOT 2
- "useEffect" is not exported by "node_modules/react/index.js"
- Usage of import.meta.env
- enums not working HOT 4
- help wanted
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.