mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
Compare commits
7 Commits
95850110ab
...
2a419514d1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a419514d1 | ||
|
|
5ca9535785 | ||
|
|
d0a1cae750 | ||
|
|
4269eeef80 | ||
|
|
60364224be | ||
|
|
a5ffe1b99b | ||
|
|
d5105b1e13 |
11
.github/depandabot.yml
vendored
Normal file
11
.github/depandabot.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: 'npm'
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: 'daily'
|
||||
|
||||
- package-ecosystem: 'github-actions'
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: 'weekly'
|
||||
2
.github/workflows/compressed-size.yml
vendored
2
.github/workflows/compressed-size.yml
vendored
@ -8,7 +8,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: pnpm/action-setup@v4
|
||||
- uses: actions/setup-node@v5
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
cache: 'pnpm'
|
||||
|
||||
2
.github/workflows/preview-release.yml
vendored
2
.github/workflows/preview-release.yml
vendored
@ -8,7 +8,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: pnpm/action-setup@v4
|
||||
- uses: actions/setup-node@v5
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
cache: 'pnpm'
|
||||
|
||||
2
.github/workflows/publish.yml
vendored
2
.github/workflows/publish.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: pnpm/action-setup@v4
|
||||
- uses: actions/setup-node@v5
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
2
.github/workflows/test-multiple-builds.yml
vendored
2
.github/workflows/test-multiple-builds.yml
vendored
@ -17,7 +17,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: pnpm/action-setup@v4
|
||||
- uses: actions/setup-node@v5
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
cache: 'pnpm'
|
||||
|
||||
2
.github/workflows/test-multiple-versions.yml
vendored
2
.github/workflows/test-multiple-versions.yml
vendored
@ -24,7 +24,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: pnpm/action-setup@v4
|
||||
- uses: actions/setup-node@v5
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
cache: 'pnpm'
|
||||
|
||||
2
.github/workflows/test-old-typescript.yml
vendored
2
.github/workflows/test-old-typescript.yml
vendored
@ -31,7 +31,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: pnpm/action-setup@v4
|
||||
- uses: actions/setup-node@v5
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
cache: 'pnpm'
|
||||
|
||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -12,7 +12,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: pnpm/action-setup@v4
|
||||
- uses: actions/setup-node@v5
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
cache: 'pnpm'
|
||||
|
||||
@ -43,10 +43,6 @@ export const useBoundStore = create(
|
||||
)
|
||||
```
|
||||
|
||||
### CodeSandbox Demo
|
||||
|
||||
https://codesandbox.io/s/zustand-state-with-url-hash-demo-f29b88?file=/src/store/index.ts
|
||||
|
||||
## Persist and Connect State with URL Parameters (Example: URL Query Parameters)
|
||||
|
||||
There are times when you want to conditionally connect the state to the URL.
|
||||
@ -150,3 +146,8 @@ export const buildShareableUrl = (params, version) => {
|
||||
The generated URL would look like (here without any encoding, for readability):
|
||||
|
||||
`https://localhost/search?fishAndBearsStore={"state":{"typesOfFish":["tilapia","salmon"],"numberOfBears":15},"version":0}}`
|
||||
|
||||
### Demo
|
||||
|
||||
- Hash: https://stackblitz.com/edit/vitejs-vite-9vg24prg
|
||||
- Query: https://stackblitz.com/edit/vitejs-vite-hyc97ynf
|
||||
|
||||
@ -39,7 +39,7 @@ export const create = (<T>() => {
|
||||
}) as typeof actualCreate
|
||||
```
|
||||
|
||||
## CodeSandbox Demo
|
||||
## Demo
|
||||
|
||||
- Basic: https://stackblitz.com/edit/zustand-how-to-reset-state-basic
|
||||
- Advanced: https://stackblitz.com/edit/zustand-how-to-reset-state-advanced
|
||||
|
||||
@ -110,6 +110,6 @@ Provide type hints when initializing empty Maps and Sets:
|
||||
|
||||
Without type hints, TypeScript infers `never[]` which prevents adding items later.
|
||||
|
||||
## CodeSandbox Demo
|
||||
## Demos
|
||||
|
||||
Basic: https://stackblitz.com/edit/vitejs-vite-5cu5ddvx
|
||||
|
||||
@ -507,11 +507,6 @@ const renderCounterWithContext = () => {
|
||||
> **Note**: without [globals configuration](https://vitest.dev/config/#globals) enabled, we need
|
||||
> to add `import { describe, test, expect } from 'vitest'` at the top of each test file.
|
||||
|
||||
**CodeSandbox Demos**
|
||||
|
||||
- Jest Demo: https://stackblitz.com/edit/jest-zustand
|
||||
- Vitest Demo: https://stackblitz.com/edit/vitest-zustand
|
||||
|
||||
### Testing Stores
|
||||
|
||||
In the next examples we are going to use `useCounterStore`
|
||||
@ -747,3 +742,8 @@ const renderCounterWithContext = (store) => {
|
||||
functions are built on top of `react-test-renderer`.
|
||||
- **Testing Implementation Details**: Blog post by Kent C. Dodds on why he recommends to avoid
|
||||
[testing implementation details](https://kentcdodds.com/blog/testing-implementation-details).
|
||||
|
||||
## Demos
|
||||
|
||||
- Jest: https://stackblitz.com/edit/jest-zustand
|
||||
- Vitest: https://stackblitz.com/edit/vitest-zustand
|
||||
|
||||
@ -136,6 +136,6 @@ You can also use [Ramda](https://ramdajs.com/):
|
||||
|
||||
Both ramda and optics-ts also work with types.
|
||||
|
||||
### CodeSandbox Demo
|
||||
### Demo
|
||||
|
||||
https://codesandbox.io/s/zustand-normal-immer-optics-ramda-updating-ynn3o?file=/src/App.tsx
|
||||
https://stackblitz.com/edit/vitejs-vite-j6bjdygu
|
||||
|
||||
@ -123,7 +123,7 @@ so since both the current state and the next state are
|
||||
equal (if you don't do it correctly),
|
||||
Zustand will skip calling the subscriptions.
|
||||
|
||||
## CodeSandbox Demo
|
||||
## Demos
|
||||
|
||||
- [Basic](https://codesandbox.io/p/sandbox/zustand-updating-draft-states-basic-demo-forked-96mkdw),
|
||||
- [Advanced](https://codesandbox.io/p/sandbox/zustand-updating-draft-states-advanced-demo-forked-phkzzg).
|
||||
- Basic: https://stackblitz.com/edit/vitejs-vite-3sgc4ejy
|
||||
- Advanced: https://stackblitz.com/edit/vitejs-vite-jxxtuyj3
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user