~firefoxreact-appvite-appsrcreduxcounter
1 itemDownload ./*

..
counterSlice.ts


countercounterSlice.ts
809 B• 4•  3 days ago•  DownloadRawClose
3 days ago•  4

{}
import { createSlice } from '@reduxjs/toolkit';
import type { PayloadAction } from '@reduxjs/toolkit';

// Define the shape of the counter state
interface CounterState {
  value: number;
}

// Initial state
const initialState: CounterState = {
  value: 0,
};

// Create a slice for the counter
const counterSlice = createSlice({
  name: 'counter',
  initialState,
  reducers: {
    increment: (state) => {
      state.value += 1;
    },
    decrement: (state) => {
      state.value -= 1;
    },
    // Optional: Action with payload
    incrementByAmount: (state, action: PayloadAction<number>) => {
      state.value += action.payload;
    },
  },
});

// Export actions
export const { increment, decrement, incrementByAmount } = counterSlice.actions;

// Export reducer
export default counterSlice.reducer;

Top
©twily.info 2013 - 2025
twily at twily dot info



2 274 760 visits
... ^ v