Skip to content

Commit b57db4f

Browse files
dai-shiirfanfandi
andauthored
docs(create): document that state cannot be read during initialization (#3569)
* 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: #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. --------- Co-authored-by: fandi <[email protected]>
1 parent f094eeb commit b57db4f

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎docs/reference/apis/create-store.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ createStore<T>()(stateCreatorFn: StateCreator<T, [], []>): StoreApi<T>
3737
#### Parameters
3838

3939
- `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` and
41+
`store` cannot be used while this function is running, only after the store has been created.
4142

4243
#### Returns
4344

‎docs/reference/apis/create.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ create<T>()(stateCreatorFn: StateCreator<T, [], []>): UseBoundStore<StoreApi<T>>
3939
#### Parameters
4040

4141
- `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` and
43+
`store` cannot be used while this function is running, only after the store has been created.
4344

4445
#### Returns
4546

0 commit comments

Comments
 (0)