If the action has no payload attached, what is the purpose of the action creator?
Example:
const lightSwitch = (
state = {on: false},
action,
) => {
switch (action.type) {
case TOGGLE:
return {...state, on: !state.on };
default: return state;
}
}
When Redux is used to use application state Incorporating into React & React Native, why does the action creator need a type but no payload?
If the action has no payload attached, what is the purpose of the action creator?
Sometimes you have a reducer that does not return to a new state based on the payload. An example is the action of switching something in the state. The reducer only needs Know the trigger action to switch attributes.
Example:
const lightSwitch = (
state = {on: false},
action ,
) => {
switch (action.type) {
case TOGGLE:
return {...state, on: !state.on };
default: return state;
}
}