# Creating a New Redux Store

In this guide, you will learn to add a new Redux store to your app. To learn more about [Redux stores in Scandi](/structure/building-blocks-summary/redux-stores.md), read the docs.

## Creating a New Store

First, we need to create a new Redux store. Using the [`scandipwa`](/developing-with-scandi/developer-tools/scandipwa-cli.md) CLI utility, you can easily create a new store with a single command. In our toy example, we will call our store `ImportantNumber`:

```bash
scandipwa create store ImportantNumber
```

You should see that new files have been created, as indicated by a success message:

```
NOTE!

     The following files have been created:
     src/store/ImportantNumber/ImportantNumber.action.js
     src/store/ImportantNumber/ImportantNumber.reducer.js
```

Feel free to implement any logic you need in the Redux store.

## Redux in Scandi

At this point, you will notice that while we have defined the store in the codebase, it is not registered in the app yet. This is because it hasn't been registered yet.

In Scandi, stores are registered in the `store/index.js` file:

{% code title="node\_modules/@scandipwa/scandipwa/src/store/index.js" %}

```javascript
import BreadcrumbsReducer from 'Store/Breadcrumbs/Breadcrumbs.reducer';
import CartReducer from 'Store/Cart/Cart.reducer';
import CategoryReducer from 'Store/Category/Category.reducer';
// [...]

/** @namespace Store/Index/getReducers */
export const getStaticReducers = () => ({
    BreadcrumbsReducer,
    CartReducer,
    CategoryReducer,
    // [...]
});

export default function injectStaticReducers(store) {
    Object.entries(getStaticReducers()).forEach(
        ([name, reducer]) => store.injectReducer(name, reducer)
    );

    return store;
}
```

{% endcode %}

As you can see, most reducers are registered in the `getStaticReducers` function. To add a new reducer, we must override this function, and add our own reducer. We must also override `injectStaticReducers` to use our new function.

{% hint style="info" %}
Confused by the object notation syntax? In JavaScript, spelling out the key name is optional if it's the same as the value variable. So writing...

```javascript
{
    BreadcrumbsReducer,
    CartReducer,
    CategoryReducer
}
```

...is the same as writing:

```javascript
{
    'BreadcrumbsReducer': BreadcrumbsReducer,
    'CartReducer': CartReducer,
    'CategoryReducer': CategoryReducer
}
```

It's just like any other JavaScript object `{}`.
{% endhint %}

## Registering the Store

So how can we override the `index.js` file? Unfortunately, at the moment, the CLI cannot automate this for us, so you need to create a new file for overriding manually:

{% code title="src/store/index.js" %}

```javascript
// import the original getStaticReducers function
// and rename it to baseGetStaticReducers
import { getStaticReducers as baseGetStaticReducers } from 'SourceStore/index';

// import our own reducer
import ImportantNumberReducer from 'Store/ImportantNumber/ImportantNumber.reducer';

// define getStaticReducers.
// this is a function that returns an object of all the reducers in the app.
// just like in the base theme...
/** @namespace TutorialCsaApp/Store/Index/getStaticReducers */
export const getStaticReducers = () => ({
    ...baseGetStaticReducers(),
    
    // ...except we also add our own reducer to the mix
    ImportantNumberReducer
});

// nothing new here, just copying the function from the base theme
// (this is necessary so that it uses our own `getStaticReducers` function
export default function injectStaticReducers(store) {
    Object.entries(getStaticReducers()).forEach(
        ([name, reducer]) => store.injectReducer(name, reducer)
    );

    return store;
}
```

{% endcode %}

Aaand that's it! If you check the Redux developer tools, you will see that your reducer is now included in the state.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.scandipwa.com/tutorials/customizing-your-theme/customizing-javascript/creating-a-new-redux-store.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
