udecode / zustand-x

Zustand store factory for a best-in-class developer experience.
https://zustand-x.udecode.dev
MIT License
328 stars 20 forks source link

Support maps in immer #27

Closed rafpaz closed 2 years ago

rafpaz commented 2 years ago

Description

When using es6 Maps inside store, immer throws the following error: Uncaught Error: [Immer] The plugin for 'MapSet' has not been loaded into Immer. To enable the plugin, import and callenableMapSet()when initializing your application..

On our app, we use immer with zustand, and just adding:

import { enableMapSet } from 'immer';
enableMapSet();

solved it.

Steps

  1. Create a store with a map object, for example:
    export const storeWithMap = createStore('storeWithMap')({ tasks: new Map<string, Task>() });
  2. App crashes with the above error

Expectation Would be really nice if it will be possible to add another property into immer's options object on createStore, for enabling maps usage.

rafpaz commented 2 years ago

Fixed in: https://github.com/udecode/zustood/pull/28