Replies: 1 comment
|
The type error when piping Modern fix (zustand v4+) — nest middleware directly: Zustand v4 replaced import { create } from 'zustand';
import { immer } from 'zustand/middleware/immer';
import { devtools, redux } from 'zustand/middleware';
const useStore = create()(
devtools(
immer(
redux(reducer, initialState)
)
)
);Why nesting works but For the exact pipe pattern (zustand v3 workaround): const createStore = pipe(
redux,
immer as any, // type-cast: immer's overload conflicts with pipe's inference
devtools,
logger,
create
);Recommended for new code — nesting with explicit type: interface State {
count: number;
increment: () => void;
}
const useStore = create<State>()(
devtools(
immer((set) => ({
count: 0,
increment: () => set((state) => { state.count++ }),
}))
)
);Reading order for nesting: outermost middleware wraps last (runs first on external calls). So |
Uh oh!
There was an error while loading. Please reload this page.
Hi does anyone know if this is possible ?
const createStore = pipe(redux, immerProduce, devtools, logger, createIm getting a type error for immer
heres my immer function
All reactions