diff --git a/.changeset/flat-boxes-explain.md b/.changeset/flat-boxes-explain.md new file mode 100644 index 0000000..341a5d4 --- /dev/null +++ b/.changeset/flat-boxes-explain.md @@ -0,0 +1,5 @@ +--- +"statery": patch +--- + +Revert the previous fix for potentially infinite rerenders -- turns out it was a user issue (the user being me!), and the fix would actually cause bigger problems elsewhere. diff --git a/src/index.ts b/src/index.ts index 4dca192..c33a770 100644 --- a/src/index.ts +++ b/src/index.ts @@ -181,7 +181,7 @@ export const useStore = (store: Store): T => { subscribedProps.forEach((prop) => { if (initialState[prop] !== store.state[prop]) { - setVersion(v + 1) + setVersion((v) => v + 1) return } }) @@ -193,14 +193,14 @@ export const useStore = (store: Store): T => { /* If there is at least one prop being updated that we're interested in, bump our local version. */ if (Object.keys(updates).find((prop) => subscribedProps.has(prop))) { - setVersion(v + 1) + setVersion((v) => v + 1) } } /* Mount & unmount the listener */ store.subscribe(listener) return () => void store.unsubscribe(listener) - }, [store, v]) + }, [store]) return new Proxy>( {},