How to setup redux store using redux toolkit Part 1

2. createSlice

A function that accepts an initial state, an object of reducer functions, and a “slice name”, and automatically generates action creators and action types that correspond to the reducers and state.
For Example

const initialState = {loading: false };

const loadingSlice = createSlice({

name: ‘loading’,

initialState,

reducers: {

enableLoader: (state: LoadingState) => {

return {

…state,

loading: true,

};

},

disableLoader: (state: LoadingState) => {

return {

…state,

loading: true,

};

},

},

});

export const { enableLoader, disableLoader } = loadingSlice.actions;

export default loadingSlice.reducer;

3. create Store

import rootReducers from ‘app/store/slice’;

import { configureStore, combineReducers } from ‘@reduxjs/toolkit’;

import React from ‘react’

import { Provider, useSelector } from ‘react-redux’;

import { View } from ‘react-native’;

const reducers = combineReducers(rootReducers);

const store = configureStore({

reducer: reducers,

});

const App = () => {

return (

<Provider store={store}>

<View>

</View>

</Provider>

);

};

export default App;

4.Now you can dispatch action and get value in your project ,

5. for further visit Part 2
https://ahtisham-adroitix.medium.com/how-to-persist-redux-store-using-redux-toolkit-part-2-c844580eb1b5
1.click here for configure store from scratch using redux toolkit
2.click here for configure persist store using redux toolkit
3.click here for configure middleware using redux toolkit
4.click here for configure redux-logger using redux toolkit

--

--

--

Software Engineer (React/React Native Developer)

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

From @Balthomeservice on Twitter

How to Optimize Performance of Your React Apps

Given When Then in Angular

Creating an E-commerce Frontend with Vue.js

Is Angular dying because of React?

how to create div without html and center div

Make the Next React Blog Site You Code Easier. Use Markdown Files.

I am getting cheaper pricing for hosting from other providers. Why is your price high?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahtisham Shahzad

Ahtisham Shahzad

Software Engineer (React/React Native Developer)

More from Medium

Flexible charts in React Native using HighCharts

Redux vs ReduxToolKit — Simplify Redux Application

React Context Get Data From API

What’s the component of React.JS/react-native?