match the typescript docs (#2856)

This commit is contained in:
Charles Kornoelje 2024-11-17 18:28:55 -05:00 committed by GitHub
parent 5a8842fbc3
commit 7980a7b9cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -180,11 +180,14 @@ store.setState({}, true) // Error
#### Handling Dynamic `replace` Flag
If the value of the `replace` flag is dynamic and determined at runtime, you might face issues. To handle this, you can use a workaround by annotating the `replace` parameter with `as any`:
If the value of the `replace` flag is dynamic and determined at runtime, you might face issues. To handle this, you can use a workaround by annotating the `replace` parameter with the parameters of the `setState` function:
```ts
const replaceFlag = Math.random() > 0.5
store.setState(partialOrFull, replaceFlag as any)
const args = [{ bears: 5 }, replaceFlag] as Parameters<
typeof useBearStore.setState
>
store.setState(...args)
```
#### Persist middlware no longer stores item at store creation