Skip to content

Commit

Permalink
Revert rerender fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hmans committed Sep 17, 2022
1 parent ed5c647 commit 5c8de24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-boxes-explain.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const useStore = <T extends IState>(store: Store<T>): T => {

subscribedProps.forEach((prop) => {
if (initialState[prop] !== store.state[prop]) {
setVersion(v + 1)
setVersion((v) => v + 1)
return
}
})
Expand All @@ -193,14 +193,14 @@ export const useStore = <T extends IState>(store: Store<T>): 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<Record<any, any>>(
{},
Expand Down

0 comments on commit 5c8de24

Please sign in to comment.