Created
July 23, 2024 14:58
-
-
Save Syden10/8be4b28e6fe5ea5e988fd1b5de5aa85d to your computer and use it in GitHub Desktop.
Redux toolkit slice template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createSlice } from '@reduxjs/toolkit'; | |
export const templateSlice = createSlice({ | |
name: 'name', | |
initialState: { | |
counter: 10 | |
}, | |
reducers: { | |
increment: (state, /* action */ ) => { | |
//! https://react-redux.js.org/tutorials/quick-start | |
// Redux Toolkit allows us to write "mutating" logic in reducers. It | |
// doesn't actually mutate the state because it uses the Immer library, | |
// which detects changes to a "draft state" and produces a brand new | |
// immutable state based off those changes | |
state.counter += 1; | |
}, | |
} | |
}); | |
// Action creators are generated for each case reducer function | |
export const { increment } = templateSlice.actions; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment