immerjs / use-immer

Use immer to drive state with a React hooks
MIT License
4.04k stars 92 forks source link

在useEffect中修改Set类型的state时,为什么要手动执行enableMapSet来允许呢? #56

Closed Highnesslin closed 4 years ago

Highnesslin commented 4 years ago

` const [state, setState] = useImmer({ listSet: new Set([]) });

useEffect(() => { setState(state => { state.listSet.add(activeRouteId); }); }, [activeKey]); Error: [Immer] The plugin for 'MapSet' has not been loaded into Immer. To enable the plugin, import and call enableMapSet() when initializing your application.`

mweststrate commented 4 years ago

import and call enableMapSet() from Immer when initializing your application.

On Wed, Jul 1, 2020 at 11:38 AM Highnesslin notifications@github.com wrote:

` const [state, setState] = useImmer({ listSet: new Set([]) });

useEffect(() => { setState(state => { state.listSet.add(activeRouteId); }); }, [activeKey]); Error: [Immer] The plugin for 'MapSet' has not been loaded into Immer. To enable the plugin, import and callenableMapSet()` when initializing your application.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/immerjs/use-immer/issues/56, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4NBDMBGRZTXARJFTUVIDRZMGYVANCNFSM4ONI4O6Q .