01. März 2022
State logic in Redux
Grundelemente für die State-Verwaltung in Redux: Creator, Reducer, Store
const ADD = "ADD"
// Reducer to handle states
const messageReducer = (state = [], action) => {
switch(action.type) {
case ADD:
return [...state, action.message]
default:
return state
}
}
// Action creator which creates the action to add a message
const addMessage = (msg) => {
return {
type: ADD,
message: msg
}
}
// Create the redux store
const store = Redux.createStore(messageReducer)
freeCodeCamp