Skip to content

Commit 2c46051

Browse files
committed
use vanilla store
(as the react store is already a bounded useStore hook)
1 parent 147f935 commit 2c46051

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

docs/guides/typescript.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,18 @@ A detailed explanation on the slices pattern can be found [here](./slices-patter
399399
400400
If you have some middlewares then replace `StateCreator<MyState, [], [], MySlice>` with `StateCreator<MyState, Mutators, [], MySlice>`. For example, if you are using `devtools` then it will be `StateCreator<MyState, [["zustand/devtools", never]], [], MySlice>`. See the ["Middlewares and their mutators reference"](#middlewares-and-their-mutators-reference) section for a list of all mutators.
401401
402-
### A bounded `useStore` hook
402+
### Bounded `useStore` hook for vanilla stores
403403
404404
```ts
405-
import { create, useStore } from 'zustand'
405+
import { useStore } from 'zustand'
406+
import { createStore } from 'zustand/vanilla'
406407

407408
interface BearState {
408409
bears: number
409410
increase: (by: number) => void
410411
}
411412

412-
const bearStore = create<BearState>()((set) => ({
413+
const bearStore = createStore<BearState>()((set) => ({
413414
bears: 0,
414415
increase: (by) => set((state) => ({ bears: state.bears + by })),
415416
}))
@@ -430,14 +431,15 @@ function useBearStore<T>(
430431
You can also make an abstract `createBoundedUseStore` if you create bounded `useStore`s often and want to DRY things up...
431432
432433
```ts
433-
import { create, useStore, StoreApi } from 'zustand'
434+
import { useStore, StoreApi } from 'zustand'
435+
import { createStore } from 'zustand/vanilla'
434436

435437
interface BearState {
436438
bears: number
437439
increase: (by: number) => void
438440
}
439441

440-
const bearStore = create<BearState>()((set) => ({
442+
const bearStore = createStore<BearState>()((set) => ({
441443
bears: 0,
442444
increase: (by) => set((state) => ({ bears: state.bears + by })),
443445
}))

0 commit comments

Comments
 (0)