Comments (19)
5.0.0-alpha.5
is published. 👍 / 👎 / 👀
from zustand.
5.0.0-alpha.4
is published. 👍 / 👎 / 👀
from zustand.
5.0.0-alpha.6
is published. CJS build was broken in alpha.4
and alpha.5
.
from zustand.
5.0.0-alpha.6
works fine! Even resolves my react-native described here #1967
from zustand.
I'm not sure if some best practices were violated that caused this problem?
Yes, you create a new reference every time in your selector function.
// an easy reproduction
const useFooStore = create((set) => ({
todos: [],
}))
// this will cause an infinite loop because of new reference every render
useFooStore((state) => state.todos.map((todo) => todo.id))
To resolve it, either use createWithEqualityFn
& shallow
or useShallow
.
This infinite-loop behavior can happen without Zustand, and Zustand follows the same behavior.
from zustand.
After using reselect, this problem was also solved.
FYI, proxy-memoize also works. https://redux.js.org/usage/deriving-data-selectors#proxy-memoize
from zustand.
5.0.0-alpha.5
works with [email protected]
from zustand.
from zustand.
Thanks for reporting.
It's an intentional breaking change in #2395.
We would like to add a note in migration guide in docs. Can you create a minimal reproduction to help the docs?
from zustand.
Maybe this ordering on "exports" can be changed for RN users of zustand ?
from zustand.
Maybe this ordering on "exports" can be changed for RN users of zustand ?
@jacargentina let me take care of that
from zustand.
@dbritto-dev I've solved it by configuring in metro.config.js
:
config.resolver.unstable_conditionNames = ['require'];
default is ['require', 'import']
so that import
was causing my problem.
from zustand.
@jacargentina nice, I found that yesterday too but I didn't have time to answer any question. We shall add it to the docs.
from zustand.
Does the readme of the v5 branch already reflect the changes that will be coming up in v5 or is there some other place where one could read about it?
from zustand.
5.0.0-alpha.6 fails
5.0.0-alpha.5 fails
from zustand.
Can you create a minimal reproduction to help the docs?
I will create an example later.
I can first describe how I encountered this problem.
I first migrated from redux toolkit to zustand^4 and everything worked fine.
Then I upgraded [email protected]
The reason for this problem may be that Redux useSelector's callback do'not need to be wrapped by useCallback.
After #2395, which may have caused the issue.
Maybe useSyncExternalStoreWithSelector would be more suitable?
from zustand.
https://stackblitz.com/edit/vitejs-vite-qvlgmz?file=src%2Fcomponents%2FTodolist.tsx
@dai-shi I have create a todo list demo with this bug.
The reason why it fails is because of the use of the useTodoFindIds function.
Of course, the actual scenario is more complicated than what is written here. I want to find a set of data and then return their IDs.
I'm not sure if some best practices were violated that caused this problem?
from zustand.
After using reselect, this problem was also solved.
For RTK users migrating to zustand@next. Maybe be more familiar with reselect.
I think this can be added to the migration manual.
from zustand.
@flq yeah, I'll add it. btw, they talk about memoizing selectors.
from zustand.
Related Issues (20)
- Re-render issue while performing open and setOpen using shadcn
- Re-render issue while performing open and setOpen using shadcn HOT 1
- type WithoutCallSignature<T>
- docs: Add suggestions about getInitialState on persist
- Cant user Array of Map type to store data
- overview of the zustand API HOT 1
- Persist storage : values are converted to strings before replacer
- Value is empty on initial render and sets after few milliseconds
- Immer Middelware Typescript error: Exported variable 'useMyStore' has or is using name 'WritableDraft' from external module "../node_modules/immer/dist/immer" but cannot be named.
- blacklist and whitelist
- Argument of type '(state: ClientStore) => Client | undefined' is not assignable to parameter of type 'ClientStore | Partial<ClientStore> | ((state: ClientStore) => ClientStore | Partial<ClientStore>)'. Type '(state: ClientStore) => Client | undefined' is not assignable to type '(state: ClientStore) => ClientStore | Partial<ClientStore>'. Type 'Client | undefined' is not assignable to type 'ClientStore | Partial<ClientStore>'. Type 'undefined' is not assignable to type 'ClientStore | Partial<ClientStore>'.ts(2345)
- 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
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.