# Creating Slice

## Redux Slice&#x20;

A **slice** is a collection of Redux reducer logic and actions for a single feature in your app, typically defined together in a single file.&#x20;

The Redux Store & Slice can be compared with Pizza & it's slices where:

* Pizza = Redux Store
* Slice = Each Feature with own Reducer logic & Action

The name comes from splitting up the root Redux state object into multiple "slices" of state. Example of creating a slice:

```javascript
// Importing the createSlice function
const createSlice = require("@reduxjs/toolkit");

// Initial state for the counter
const initialState = {
  count: 0,
};

// Creating a counter slice using the createSlice function
const counterSlice = createSlice({
  // Name of the slice
  name: "counter",

  // Initial state for the slice
  initialState: initialState,

  // Reducers define how the state should be updated based on dispatched actions
  reducers: {
    // Reducer for incrementing the count
    increment: (state, action) => {
      state.count++; // Incrementing the count property in the state
    },

    // Reducer for decrementing the count
    decrement: (state, action) => {
      state.count--; // Decrementing the count property in the state
    },
  },
});

// Exporting the reducer function generated by createSlice
module.exports = counterSlice.reducer;

// Exporting the actions generated by createSlice
module.exports.counterActions = counterSlice.actions;

```
