Payload in Response and Response

When Redux is used to enable application state in React and React Native, why is a type required in the action creator, but no payload required?

What is the purpose of the action creator if the payload is not attached to the action?

+4
source share
2 answers

Sometimes you have a gearbox that does not return a new state based on the payload. An example is an action that switches something in a state. The gearbox just had to know that the action was started to switch ownership. Example:

const lightSwitch = (
  state = {on: false},
  action,
) => {
  switch (action.type) {
    case TOGGLE:
      return { ...state, on: !state.on };
    default: return state;
  }
}
0
source

Redux - /. :

export default (state = { isFetching: false }, action) => {
  switch(action.type) {
    case START_FETCHING_POSTS:
      return { ...state, isFetching: true };
    case STOP_FETCHING_POSTS:
      return { ...state, isFetching: false };
    default:
      return state;
  }
};

: const action = { type: START_FETCHING_POSTS }

0

Source: https://habr.com/ru/post/1672304/


All Articles