You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/xstate-store.mdx
+39-3
Original file line number
Diff line number
Diff line change
@@ -302,12 +302,48 @@ store.inspect(inspector);
302
302
303
303
## Using Immer
304
304
305
-
If you want to use [Immer](https://immerjs.github.io/immer/) to update the `context`, you can do so by passing in the `produce` function as the first argument to `createStoreWithProducer(producer, …)`.
305
+
You can use the `produce(…)` function from [Immer](https://immerjs.github.io/immer/) to update the `context`in transitions:
This API is deprecated. Use `produce` from [Immer](https://immerjs.github.io/immer/) or similar libraries directly with `createStore(…)` instead.
337
+
338
+
:::
339
+
340
+
In previous versions of `@xstate/store`, you could use the `createStoreWithProducer(…)` function to pass in a producer function to update the `context` for every transition. This will not be supported in future versions of `@xstate/store`. Instead, you can use the `produce(…)` function from [Immer](https://immerjs.github.io/immer/) or similar libraries directly with `createStore(…)`.
341
+
342
+
```ts
343
+
import { createStore } from'@xstate/store';
309
344
import { produce } from'immer';
310
345
346
+
// Deprecated API
311
347
const store =createStoreWithProducer(produce, {
312
348
context: { count: 0, todos: [] },
313
349
on: {
@@ -325,7 +361,7 @@ const store = createStoreWithProducer(produce, {
325
361
// ...
326
362
```
327
363
328
-
Note that you cannot use the object assigner syntax when using `createStoreFromProducer(…)`, nor is it even necessary.
0 commit comments