Skip to content
Myr

docs(create): document that state cannot be read during initialization (#3569)

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

* docs(create): document that state cannot be read during initialization The store api passed to the state creator function is not usable for reading state while that function runs: get() and store.getState() return undefined, and store.getInitialState() throws "Cannot access 'initialState' before initialization". Per the discussion, this is a designed limitation rather than a bug, so document it in the create and createStore troubleshooting sections. Ref: https://github.com/pmndrs/zustand/discussions/3529 * docs(create): shorten init-time state access note to a one-line caveat Per review feedback, the troubleshooting section was too long for such a subtle behavior. Replace it with a one-line note on the stateCreatorFn parameter in both create and createStore. ---------

authored by Daishi Kato · committed by GitHub · parent f094eeb · Browse files · 2 files+4 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: fandi <irfanfandi38@gmail.com>

Diff stats

2 files+4 added−2 removed

  • other:+4 added−2 removed

2 files+4 added−2 removed

modified:docs/reference/apis/create-store.md+2 added-1 removed
35 unmodified lines
3637#### Parameters3839- `stateCreatorFn`: A function that takes `set` function, `get` function and `store` as arguments.40 Usually, you will return an object with the methods you want to expose.40 Usually, you will return an object with the methods you want to expose. Note that `set`, `get` and41 `store` cannot be used while this function is running, only after the store has been created.4243#### Returns4445`createStore` returns a vanilla store that exposes API utilities, `setState`, `getState`,
473 unmodified lines
modified:docs/reference/apis/create.md+2 added-1 removed
37 unmodified lines
3839#### Parameters4041- `stateCreatorFn`: A function that takes `set` function, `get` function and `store` as arguments.42 Usually, you will return an object with the methods you want to expose.42 Usually, you will return an object with the methods you want to expose. Note that `set`, `get` and43 `store` cannot be used while this function is running, only after the store has been created.4445#### Returns4647`create` returns a React Hook with API utilities, `setState`, `getState`, `getInitialState` and
525 unmodified lines