Skip to content
Myr

feat(types): Make ExtractState public (#2935)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* make ExtractState public and move it to vanilla * add docs on the matter * Update vanilla.ts ---------

authored by Mordechai Dror · committed by GitHub · parent 929b547 · Browse files · 3 files+18 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>

Diff stats

3 files+18 added−2 removed

  • other:+18 added−2 removed

3 files+18 added−2 removed

modified:docs/guides/typescript.md+15 added
159 unmodified lines
160</details>161162Note that we don't use the curried version when using `combine` because `combine` "creates" the state. When using a middleware that creates the state, it isn't necessary to use the curried version because the state now can be inferred. Another middleware that creates state is `redux`. So when using `combine`, `redux`, or any other custom middleware that creates the state, we don't recommend using the curried version.163164If you want to infer state type also outside of state declaration, you can use the `ExtractState` type helper:165166```ts167import { create, ExtractState } from 'zustand'168import { combine } from 'zustand/middleware'169170type BearState = ExtractState<typeof useBearStore>171172const useBearStore = create(173 combine({ bears: 0 }, (set) => ({174 increase: (by: number) => set((state) => ({ bears: state.bears + by })),175 })),176)177```178179## Using middlewares180181You do not have to do anything special to use middlewares in TypeScript.182
360 unmodified lines
modified:src/react.ts+1 added-2 removed
modified:src/vanilla.ts+2 added