React Redux
Redux:
Reudux is predictable state container for javascript apps.
1 its library for javascript apps[can use react angular viewjs]
2.its state container
3.in redux,all state transitions are explicit and it is
possible to keep track of them.//or the changes in the state is predictable.
The data in react always
flows from parent to child component
which makes it unidirectional
parent to child flow
not
child to parent
so we can work with prop drilling
the data stroe into app.js
so we have to pass from one to another
or
context APi,use Context in react hooks
/useReducer hooks
........................................
Redux is state management library with java script
we can use it with react angular vue and vanilla js
for state management
why need
user change one part of ui
then data has to change in other part of ui immediately
sync
state management solutions
[flux :facebook]
one store for all application state(Store) synchronized easy
like its database
if you update data so update in store
Redux:
centralizes application's state
make data flow transparent and predictable
easy debugging
Like add cart
all the data is sync
food delivery application
redux dev tool:for debuging redux appliction tool in chrome
event action.... deispatcher().. store .. reducer event handler....store
steps:
design the store
define the actions
create a reducer
string is serializable
no is not describable
so action is type:
Action:what to do increment or decrement
describes what happend
its object have a type field(prperty) that
indicates the type of action being performed
type property is string constant
+and - both 2 action
what to do
what happend
the only way your application can interact with the store
action creator() pure function which creates
an action
or returns an action
reusable
Reducer:useReducer hook
function that take the current state and an action
as arguments and return a new state
//(previousState,action)=>newstate :---reducer means
ties the store and action together
contains state and action
specify how the app state changes in response to actions
sent to the store
store:
one store for the entire application
holds the state
object which holds the state of the application
store inside
function:
createStore()
dispatch(action) allows state to be upadate
getstate() allows acces to the state
subscribe():registers listeners
redux store brings together the state
actions and reducers
we will have a single store in a Redux application
Comments
Post a Comment