diff --git a/src/with-slices.ts b/src/with-slices.ts index 906134c..659cbf0 100644 --- a/src/with-slices.ts +++ b/src/with-slices.ts @@ -45,9 +45,14 @@ export function withSlices< config.actions, )) { state[actionName] = (...args: unknown[]) => { - set(((prevState: Record) => ({ - [config.name]: actionFn(...args)(prevState[config.name]), - })) as never); + set(((prevState: Record) => { + const prevSlice = prevState[config.name]; + const nextSlice = actionFn(...args)(prevSlice); + if (Object.is(prevSlice, nextSlice)) { + return prevState; + } + return { [config.name]: nextSlice }; + }) as never); }; } }