Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pmndrs/zustand
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.5.1
Choose a base ref
...
head repository: pmndrs/zustand
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.5.2
Choose a head ref
  • 10 commits
  • 10 files changed
  • 11 contributors

Commits on Feb 22, 2024

  1. Update ssr-and-hydration.md (#2353)

    * Update ssr-and-hydration.md
    
    Small typo
    
    * Update docs/guides/ssr-and-hydration.md
    
    Co-authored-by: Blazej Sewera <code@sewera.dev>
    
    ---------
    
    Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
    Co-authored-by: Blazej Sewera <code@sewera.dev>
    3 people authored Feb 22, 2024
    Copy the full SHA
    08d1376 View commit details
  2. updated getting-started doc with more examples (#2348)

    * updated readme with more examples
    
    * moved example to docs from readme
    
    * formatted code with Prettier
    
    ---------
    
    Co-authored-by: Ankit Sagar <ankit.sagar@telnesstech.com>
    yankycranky and ankit-telness authored Feb 22, 2024
    Copy the full SHA
    3c6dc2d View commit details

Commits on Feb 28, 2024

  1. Fix typo in prevent-rerenders-with-use-shallow.md (#2364)

    cheeZery authored Feb 28, 2024
    Copy the full SHA
    827d5aa View commit details

Commits on Feb 29, 2024

  1. Enable usage of Corepack (#2366)

    Corepack chooses package manager to use with the
    field `packageManager`. For users using Yarn
    through Corepack, this is a real convenience.
    
    Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
    onlined and dai-shi authored Feb 29, 2024
    Copy the full SHA
    16b0ebf View commit details
  2. refactor: Use for..of instead of C-style for (#2374)

    onlined authored Feb 29, 2024
    Copy the full SHA
    41924df View commit details

Commits on Mar 1, 2024

  1. docs: adding note about middlewares and slices (#2378)

    * docs: adding note about middlewares and slices
    
    * chore: updating slices note
    
    Co-authored-by: Blazej Sewera <code@sewera.dev>
    
    ---------
    
    Co-authored-by: Blazej Sewera <code@sewera.dev>
    Cadienvan and sewera authored Mar 1, 2024
    Copy the full SHA
    1392c51 View commit details

Commits on Mar 2, 2024

  1. fix: return type of persist migrate function changed to PersistedState (

    #2360)
    
    Co-authored-by: Bob Deprez <bob.deprez@zf.com>
    bobdepreziz and Bob Deprez authored Mar 2, 2024
    Copy the full SHA
    9cb1c67 View commit details
  2. build: target es2018 (#2361)

    dai-shi authored Mar 2, 2024
    Copy the full SHA
    453b3a6 View commit details
  3. chore(deps): update dev dependencies (#2379)

    dai-shi authored Mar 2, 2024
    Copy the full SHA
    96d6bb2 View commit details
  4. 4.5.2

    dai-shi committed Mar 2, 2024
    Copy the full SHA
    6f61b76 View commit details
4 changes: 2 additions & 2 deletions .github/workflows/test-multiple-versions.yml
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ jobs:
- 18.0.0
- 18.1.0
- 18.2.0
- 18.3.0-canary-a9cc32511-20240215
- 0.0.0-experimental-a9cc32511-20240215
- 18.3.0-canary-2f8f77602-20240229
- 0.0.0-experimental-2f8f77602-20240229
devtools-skip:
- CI-MATRIX-NOSKIP
include:
1 change: 1 addition & 0 deletions docs/getting-started/introduction.md
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ const useStore = create((set) => ({
bears: 0,
increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
removeAllBears: () => set({ bears: 0 }),
updateBears: (newBears) => set({ bears: newBears }),
}))
```

2 changes: 1 addition & 1 deletion docs/guides/prevent-rerenders-with-use-shallow.md
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ useMeals.setState({
})
```

This change causes `BearNames` rerenders even tho the actual output of `names` has not changed according to shallow equal.
This change causes `BearNames` rerenders even though the actual output of `names` has not changed according to shallow equal.

We can fix that using `useShallow`!

2 changes: 2 additions & 0 deletions docs/guides/slices-pattern.md
Original file line number Diff line number Diff line change
@@ -113,6 +113,8 @@ export const useBoundStore = create(
)
```

Please keep in mind you should only apply middlewares in the combined store. Applying them inside individual slices can lead to unexpected issues.

## Usage with TypeScript

A detailed guide on how to use the slice pattern in Zustand with TypeScript can be found [here](./typescript.md#slices-pattern).
2 changes: 1 addition & 1 deletion docs/guides/ssr-and-hydration.md
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ that runs in the browser. The right way to "hydrate" a component is by using `hy

### React

Let's say we want to render an statefull app using react. In order to do that we need to
Let's say we want to render a stateful app using React. In order to do that we need to
use `express`, `react`, `react-dom/server` and `react-dom/client`.

Let's dive into that:
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zustand",
"private": true,
"version": "4.5.1",
"version": "4.5.2",
"description": "🐻 Bear necessities for state management in React",
"main": "./index.js",
"types": "./index.d.ts",
@@ -205,12 +205,12 @@
"use-sync-external-store": "1.2.0"
},
"devDependencies": {
"@babel/core": "^7.23.9",
"@babel/core": "^7.24.0",
"@babel/plugin-external-helpers": "^7.23.3",
"@babel/plugin-transform-react-jsx": "^7.23.4",
"@babel/plugin-transform-runtime": "^7.23.9",
"@babel/plugin-transform-runtime": "^7.24.0",
"@babel/plugin-transform-typescript": "^7.23.6",
"@babel/preset-env": "^7.23.9",
"@babel/preset-env": "^7.24.0",
"@redux-devtools/extension": "^3.3.0",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-babel": "^6.0.4",
@@ -219,18 +219,18 @@
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@testing-library/react": "^14.2.1",
"@types/node": "^20.11.19",
"@types/react": "^18.2.55",
"@types/node": "^20.11.24",
"@types/react": "^18.2.61",
"@types/react-dom": "^18.2.19",
"@types/use-sync-external-store": "^0.0.6",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"@vitest/coverage-v8": "0.33.0",
"@vitest/ui": "0.33.0",
"concurrently": "^8.2.2",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.20.0",
"eslint": "^8.56.0",
"esbuild": "^0.20.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.29.1",
@@ -266,5 +266,6 @@
"react": {
"optional": true
}
}
},
"packageManager": "yarn@1.22.21+sha256.dbed5b7e10c552ba0e1a545c948d5473bc6c5a28ce22a8fd27e493e3e5eb6370"
}
9 changes: 5 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -25,10 +25,11 @@ function getBabelOptions(targets) {
}
}

function getEsbuild(target, env = 'development') {
function getEsbuild(env = 'development') {
return esbuild({
minify: env === 'production',
target,
target: 'es2018',
supported: { 'import-meta': true },
tsconfig: path.resolve('./tsconfig.json'),
})
}
@@ -73,7 +74,7 @@ function createESMConfig(input, output) {
delimiters: ['\\b', '\\b(?!(\\.|/))'],
preventAssignment: true,
}),
getEsbuild('node12'),
getEsbuild(),
],
}
}
@@ -162,7 +163,7 @@ function createSystemConfig(input, output, env) {
delimiters: ['\\b', '\\b(?!(\\.|/))'],
preventAssignment: true,
}),
getEsbuild('node12', env),
getEsbuild(env),
],
}
}
5 changes: 4 additions & 1 deletion src/middleware/persist.ts
Original file line number Diff line number Diff line change
@@ -126,7 +126,10 @@ export interface PersistOptions<S, PersistedState = S> {
* A function to perform persisted state migration.
* This function will be called when persisted state versions mismatch with the one specified here.
*/
migrate?: (persistedState: unknown, version: number) => S | Promise<S>
migrate?: (
persistedState: unknown,
version: number,
) => PersistedState | Promise<PersistedState>
/**
* A function to perform custom hydration merges when combining the stored state with the current one.
* By default, this function does a shallow merge.
6 changes: 3 additions & 3 deletions src/vanilla/shallow.ts
Original file line number Diff line number Diff line change
@@ -37,10 +37,10 @@ export function shallow<T>(objA: T, objB: T) {
if (keysA.length !== Object.keys(objB).length) {
return false
}
for (let i = 0; i < keysA.length; i++) {
for (const keyA of keysA) {
if (
!Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||
!Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])
!Object.prototype.hasOwnProperty.call(objB, keyA as string) ||
!Object.is(objA[keyA as keyof T], objB[keyA as keyof T])
) {
return false
}
775 changes: 394 additions & 381 deletions yarn.lock

Large diffs are not rendered by default.