top of page

Redux & Redux Toolkit

  • Writer: Anand Nerurkar
    Anand Nerurkar
  • Sep 7, 2023
  • 2 min read

Updated: May 21, 2024


ree

ree
ree

ree

As per above digram- component hierarchy, App is the root one.


let us consoder component E, it has one variable whose state we need to transfer to Component D. We can do it by

  1. transferring state to C, then to A and finally to D


let us consoder component E, it has one variable whose state we need to transfer to Component I. We can do it by

  1. transferring state to C, then to A -> App ->B-->H--->I

we need to traverse the hierachy to transfer state , it reduces performance. so this is where Redux come into place.


Redux has store component which store the state of component , this store component can be subscribed by n no of component who want that state. Thus any changes in the state of a component will be set in Redux Store and Redux Store will tranfer that state to its subscribed component.

ree

Principles Of Redux Pattern

==

create react app with below command


ree

install redux packages


npm install redux react-redux


ree

ree

ree

ree

ree

ree

let us add product component- function based component

ree

Add this componenet to app.js


ree

ree

let us add redux folder-product folder-action


ree

create ActionType.js as below


ree


ree

create Reducer- ProductReducer as below

ree

create store.js as below

ree

goto app,js and inport provider and include provider store as below

provider is global one.

ree

in store.js, we are using legacy store ,instead we will use latest store which is provided by redux toolkit, so install it


ree

once installed, we will make use of latest store -cratestore as below


ree


ree

Now we need to create subscribe and dispatch so that we can complete redux flow.


edit productcontainer.js ,will add fucntion which accept state as input and convert it to object. this obejct value is being used as props in component.

ree

will add one more function that represent dispatch ,accept dispatch as input and return function which initiate action



ree


ree

now we will use redux connect functionality to connect subscribe and dispatch action, import connect from react-redux as below




ree

ree

now we will call click event on make order button and call dispatch function on props as below


ree

when click on makeorder,


ree

ree

 
 
 

Recent Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
  • Facebook
  • Twitter
  • LinkedIn

©2024 by AeeroTech. Proudly created with Wix.com

bottom of page