From d38882ded9768c77153c0809fab7606106b07d53 Mon Sep 17 00:00:00 2001 From: exuanbo Date: Sat, 7 Sep 2024 10:20:51 +0100 Subject: [PATCH] fix: update stale state in reducer --- src/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3b5b9ef..b2368a5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,8 +10,8 @@ export function useZustand( const state = store.getState(); const [[sliceFromReducer, storeFromReducer], rerender] = useReducer< Reducer< - readonly [Slice, StoreApi, State], - readonly [Slice, StoreApi, State] | undefined + [Slice, StoreApi, State], + [Slice, StoreApi, State] | undefined >, undefined >( @@ -25,6 +25,7 @@ export function useZustand( } const nextSlice = selector(nextState); if (areEqual(prev[0], nextSlice) && prev[1] === store) { + prev[2] = nextState; return prev; } return [nextSlice, store, nextState];