profile
viewpoint

Ask questionsUndo/ Redo

Hey, I was wondering if you guys have a recommended way for implementing undo/redo in RTK. redux-undo is incompatible and it looks like we can't use immer patches because createReducer doesn't use the produce function.

reduxjs/redux-toolkit

Answer questions rjdlee

Oh.. Now I understand. I have to wrap my initialState type with StateWithHistory.

createSlice({
    initialSlice: {} as StateWithHistory<MyState>,
    name: 'mySlice',
    reducers: {
        addLane: undoable<MyState>(produce((state: MyState, action: PayloadAction<MyObject>) => {
             state[ action.payload.id ] = action.payload;
        })),
    }
});
useful!
source:https://uonfu.com/
answerer
Richard Lee rjdlee rjdlee.com I am a frontend software engineer focused on rapidly delivering engaging user experiences without sacrificing long term cadence.
Github User Rank List