Skip to content

Instantly share code, notes, and snippets.

@MOgorodnik
Created September 3, 2020 13:59
Show Gist options
  • Save MOgorodnik/79785c5b387143d94f4e3126393d840e to your computer and use it in GitHub Desktop.
Save MOgorodnik/79785c5b387143d94f4e3126393d840e to your computer and use it in GitHub Desktop.
redux_start-principle
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