Redux toolkit | How to get started
Tags: redux, reduxtoolkit, statemanagement, react
Published: 2022-09-20 19:41:30

---
title: Redux toolkit | How to get started
published: true
date: 2022-09-19 12:08:48 UTC
tags: redux, reduxtoolkit, statemanagement, reactjs
canonical_url: 
---

![auraqule](https://cdn-images-1.medium.com/max/1024/0*XFJJdYhhSprNHJRE)

### What is REDUX?

Redux is a predictable state management tool for JavaScript apps. It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test. On top of that, it provides a great developer experience, such as live code editing combined with a time traveling debugger.

You can use Redux together with React, or with any other view library. It is tiny (2kB, including dependencies), but has a large ecosystem of addons available.

> _The simplest way to pass data from a parent to a child in a React Application is by passing it on to the child’s props. But an issue arises when a deeply nested child requires data from a component higher up in the tree. If we pass on the data through the props, every single one of the children would be required to accept the data and pass it on to its child, leading to prop drilling, a terrible practice in the world of React. To solve the prop drilling issue in the world of REACT, we have State Management Solutions like Context API and Redux, but today we’ll focusing on REDUX._

According to REDUX documentation in 👉 [https://redux.js.org](https://auraqule.hashnode.dev/Link)

> _Redux Toolkit is our official recommended approach for writing Redux logic. It wraps around the Redux core, and contains packages and functions that we think are essential for building a Redux app. Redux Toolkit builds in our suggested best practices, simplifies most Redux tasks, prevents common mistakes, and makes it easier to write Redux applications._

### How to use REDUX

The whole global state of your app is stored in an object tree inside a single **STORE**. The only way to change the state tree is to create an **action** , an object describing what happened, and **dispatch** it to the store. To specify how state gets updated in response to an action, you write pure **reducer** functions that calculate a new state based on the old state and the action.

Step 1- Create a REDUCER.

```
import { createSlice } "@reduxjs/toolkit";
export const slice = createSlice({ name: "slice-name", initialState: { }, reducers: { func01: (state) = > { }, } }); 
export const { func01 } = slice.actions; 
export default slice.reducer;
```

Step 2- Configure the store.

```
import { configureStore } from "@reduxjs/toolkit"; 
import reducer from "./reducer"; 
export default configureStore({ reducer: { reducer: reducer } });
```

Step 3- Make the STORE available for data consumption.

```
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import App from './App.jsx'
import store from './store';

ReactDOM.render(
 <Provider store={store}>
 <App />
 </Provider>,
 document.getElementById("root")
);
```

Step 4- Use state or Dispatch Actions.

```
import { useSelector, useDispatch } from 'react-redux';
import { func01 } from './redux/reducer';

const Component = () => {
 const reducerState = useSelector((state) => state.reducer);
 const dispatch = useDispatch();
 const doSomething = () = > dispatch(func01) 
 return (
 <>
 {/* ... */}
 </>
 );
}
export default Component;
```

### Conclusion

Redux Toolkit is a great option for both beginners and developers who wants to reduce the amount of boilerplate code in Redux. It allows us to write cleaner and more readable code while keeping the Redux flow and pattern.

Thank you for reading. I hope this article has been helpful in getting you started with understanding Redux and using Redux Toolkit in your applications. Cheers! 😀

If you have any question or comments, feel free to drop it in the comment section below ✌

_Originally published at_ [_https://auraqule.hashnode.dev_](https://auraqule.hashnode.dev/redux-toolkit-state-management-how-to-get-started)_._