Creating Actions

In notebook:
FrontEndMasters Intermediate React
Created at:
2019-06-25
Updated:
2019-08-15
Tags:
React libraries JavaScript

https://frontendmasters.com/courses/intermediate-react-v2/creating-actions/

Using the Reducers

Create the folder actionCreators. Some people prefer to use directly the action, Brian will use actionCretors.

   //    ****        actionCreators/changeLocation.js        ****

export default function changeLocation(location) {
  return { type: "CHANGE_LOCATION", payload: location };
}

You can directly dispatch the actions ({ type: "CHANGE_LOCATION", payload: location }), it's Ok too, the above function returns the action.

   //    ****        actionCreators/changeTheme.js        ****

export default function changeTheme(theme) {
  return { type: "CHANGE_THEME", payload: theme };
}