aboutsummaryrefslogblamecommitdiff
path: root/src/features/counter/counterSlice.js
blob: 4cb999356a53a01afd6d3a3fe29ad9982cd14dff (plain) (tree)
1
2
3
4
5
6
7
                                              

                                         



                  









                                                                             
     
    
  
 

                                                               
 
                                   
import { createSlice } from '@reduxjs/toolkit'

export const counterSlice = createSlice({
  name: 'counter',
  initialState: {
    value: 0,
  },
  reducers: {
    increment: (state) => {
      // 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.value += 1;
    },
    decrement: (state) => {
      state.value -= 1;
    }
  },
})

// Action creators are generated for each case reducer function
export const { increment, decrement } = counterSlice.actions

export default counterSlice.reducer