Created
September 3, 2020 13:59
-
-
Save MOgorodnik/79785c5b387143d94f4e3126393d840e to your computer and use it in GitHub Desktop.
redux_start-principle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {createStore} from 'redux'; | |
const initState = { | |
car: 'Audi', | |
color: 'red' | |
} | |
// console.log('initState', initState) | |
function reducer(state = initState, action) { | |
// debugger | |
// console.log(state) | |
// console.log(action) | |
switch (action.type) { | |
case 'CHANGE_CAR': | |
return {...state, car: action.payload} | |
break; | |
case 'CHANGE_COLOR': | |
return {...state, color: action.payload} | |
break; | |
default: | |
break; | |
} | |
return state | |
} | |
const store = createStore(reducer); | |
console.table(store.getState()) | |
const changeCar = { | |
type: 'CHANGE_CAR', | |
payload: 'BMV' | |
} | |
const changeColor = { | |
type: 'CHANGE_COLOR', | |
payload: 'white' | |
} | |
store.dispatch(changeCar) | |
console.table(store.getState()) | |
store.dispatch(changeColor) | |
console.table(store.getState()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment