Search code examples
javascriptreduxredux-toolkit

Reset state to initial with redux-toolkit


I need to reset current state to initial state. But all my attempts were unsuccessful. How can I do it using redux-toolkit?

const showOnReviewSlice = createSlice({
  name: 'showOnReview',
  initialState: {
    returned: [],
  },
  reducers: {
    reset(state) {
      //here I need to reset state of current slice
    },
  },
});


Solution

  • Something like this:

    const intialState = {
      returned: []
    }
    
    const showOnReviewSlice = createSlice({
        name: 'showOnReview',
        initialState,
        reducers: {
            reset: () => initialState
        }
    });