Skip to content

Commit

Permalink
Use useLayoutEffect instead of usEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
hmans committed Jul 26, 2022
1 parent fb6969f commit d2eb9b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-emus-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"statery": minor
---

**Fixed:** `useStore` now hooks into the store using `useLayoutEffect`, not `useEffect`
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from "react"
import { useLayoutEffect, useRef, useState } from "react"

/*
Expand Down Expand Up @@ -157,7 +157,7 @@ export const useStore = <T extends State>(store: Store<T>): T => {
const subscribedProps = useConst(() => new Set<keyof T>())

/* Subscribe to changes in the store. */
useEffect(() => {
useLayoutEffect(() => {
const listener: Listener<T> = (updates: Partial<T>) => {
/* If there is at least one prop being updated that we're interested in,
bump our local version. */
Expand Down

0 comments on commit d2eb9b4

Please sign in to comment.