v5.0.0
πππ Zustand v5 π»π»π»
TL;DR
- No new features
- Drop many old things
- Migration from v4 should be smooth.
Changes in v5
- Drop default exports
- Drop deprecated features
- Make React 18 the minimum required version
- Make use-sync-external-store a peer dependency (required for
createWithEqualityFn
anduseStoreWithEqualityFn
inzustand/traditional
) - Make TypeScript 4.5 the minimum required version
- Drop UMD/SystemJS support
- Organize entry points in the package.json
- Drop ES5 support
- Stricter types when setState's replace flag is set
- Persist middleware behavioral change
- Other small improvements (technically breaking changes)
Migration Guide
Read the migration guide carefully:
https://github.com/pmndrs/zustand/blob/main/docs/migrations/migrating-to-v5.md
Frequently Reported Issue
During the RC period, some users encountered the following infinite loop error:
Uncaught Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
This case was already a non-ideal behavior in v4 but appears more explicitly as an error in v5. While there are several ways to resolve this, using useShallow
often fixes the problem.
What's Changed
- v5 by @dai-shi in #2138
- Fix Immer type inference for
setState
by @chrisvander in #2696
New Contributors
- @abernier made their first contribution in #2674
- @tthallos made their first contribution in #2501
- @sagiereder made their first contribution in #2673
- @melutovich made their first contribution in #2692
- @rgksugan made their first contribution in #2695
- @Anuovec made their first contribution in #2708
- @EthanRBrown made their first contribution in #2717
- @mym0404 made their first contribution in #2730
- @87xie made their first contribution in #2745
- @f312213213 made their first contribution in #2761
- @DanThemes made their first contribution in #2764
- @chaficnajjar made their first contribution in #2770
- @goosewobbler made their first contribution in #2781
- @Amyssyko made their first contribution in #2784
- @MartinGamesCZ made their first contribution in #2785
Full Changelog: v4.5.5...v5.0.0