The Redux Introduction in react and applications .
Lalith86
11 views
22 slides
May 30, 2024
Slide 1 of 22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
About This Presentation
This is redux concept in react
Size: 711.9 KB
Language: en
Added: May 30, 2024
Slides: 22 pages
Slide Content
1
Redux
IVAN LOVRIĆ
2
Redux
Open-source JavaScript library
Designed for managing application state
3
Redux
Simple
No setup
Complex
Significant setup
JS jQuery React React + Redux
Complex data flows
Inter-component communication
Non-hierarchical data
Many actions
Same data used in multiple places
WHEN DO I NEED REDUX?
4
Redux
ACTIONS
REDUCERS
STORE
PURE FUNCTIONS
IMMUTABILITY
WHAT ARE WE GOING TO LEARN:
REDUX
…AND MORE
5
Redux
One immutable store Actions trigger changes Reducers update state
3 PRINCIPLES OF REDUX
6
Redux
REDUX FLOW
Action
Store
React
Reducers
functionappReducer(state, action) {
switch(action.type){
caseRATE_COURSE:
// return new state
}
}
{ type: RATE_COURSE, rating: 5 }
Notified via React-Redux
8
Redux
function myReducer(state, action){
switch(action.type){
caseINCREMENT_COUNTER:
// return new state based on action passed
}
}
REDUX REDUCER
“state is read-only”
9
Redux
REDUX REDUCER
“changes are made with pure functions”
// Pure functions
functionsquare(x) {
returnx* x;
}
functionsquareAll(items) {
returnitems.map(square);
}
10
Redux
REDUX REDUCER
“changes are made with pure functions”
// Impure functions
functionsquare(x) {
updateXInDatabase(x);
returnx* x;
}
functionsquareAll(items) {
for(leti= 0; i< items.length; i++) {
items[i] = square(items[i]);
}
}
20
Redux
ACTIONS
Represent user intent
Must have a type
STORE
dispatch, subscribe, getState…
IMMUTABILITY
Just return a new copy
REDUCERS
Must be pure
Multiple per app
Slice of state