- f18b084: Fixes SSR issue with Next.js requiring the getServerSnapshot argument with useSyncExternalStore.
- 8928b16: Statery's React hooks now internally use React 18's new
useSyncExternalStore
hook. This simplifies the library implementation and makes sure that store updates don't cause UI drift. (Thanks @smartinio!) - 8c555e2: This package is now built using TypeScript 5.1.
- a9923df: Fixed: The library recently started using
useLayoutEffect
instead ofuseEffect
, breaking it in SSR environments, where usage of that hook throws errors. This has been fixed. (Thanks @daveschumaker!)
- 5c8de24: 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.
- c69ab20: Updating the same state property multiple times within the same React side effect would sometimes trigger multiple rerenders of the component, resulting in an infinite loop (for example when writing into the store in a
ref
function.) This has now been fixed.
- d2eb9b4: Fixed:
useStore
now hooks into the store usinguseLayoutEffect
, notuseEffect
- 53fff47: Refreshed all of the package's dependencies and brushed up its test setup.
- 5b64a96: Switched the library's build tool to Preconstruct. If everything breaks, it's on me! 🎉
- 53fff47: Statery now requires React 18 and up!
- 75d0a40: Simplify types.
- da27eba:
set
now takes a second options argument. The only available option so far isforceNotify
; when set to true, all updated properties will be notified, regardless of referential equality to the previous value.
- a5f5533:
useStore
will now force the component to re-render if a change was detected between the React render/reconcile stage and the invocation of the layout effect that actually sets up the subscription listener. This improves reactivity in situations where values were changed in the store during the render phase, or imperatively from outside of your React component tree.
- 5b64a96: Switched the library's build tool to Preconstruct. If everything breaks, it's on me! 🎉
- a5f5533:
useStore
will now force the component to re-render if a change was detected between the React render/reconcile stage and the invocation of the layout effect that actually sets up the subscription listener. This improves reactivity in situations where values were changed in the store during the render phase, or imperatively from outside of your React component tree.
- 75d0a40: Simplify types.
- da27eba:
set
now takes a second argumentforceNotify
; when set to true, all updated properties will be notified, regardless of referential equality to the previous value.
- d2eb9b4: Fixed:
useStore
now hooks into the store usinguseLayoutEffect
, notuseEffect
- 53fff47: Refreshed all of the package's dependencies and brushed up its test setup.
- 53fff47: Statery now requires React 18 and up!
- Changed: Slightly improved typings. Most importantly,
store.state
is now typed as readonly, which should make Typescript et al warn you if you're trying to directly mutate the state object. - Changed: Statery now uses Typescript 4.2.
- Fixed: When subscribers were invoked, the store's state had not yet been updated to reflect the incoming changes. This has now been fixed.
- Minor Breaking Change: The
set
function will now filter incoming updates and discard any that don't actually change the value that is currently in the store. Listeners will only receive the actual changes to a store, and components will only re-render when a watched store property has actually changed to a new value. This change was made to allow for easier integration with libraries like Immer that produce a complete new version of the store.
set
now returns the updated version of the state (instead ofvoid
.)
- Breaking change: The nature of
subscribe
callbacks has changed. Whenever a store is updated, each listener callback will now be invoked exactly once, with an object containing the applied changes as the first argument, and the current version of the state as the second. - The bundles generated for the NPM package are now minified through terser.
- No more "Rendered fewer hooks than expected" surprises! (#1)
- First release. Exciting times!