Next, we define the post action creators:
- Create a new src/actions/posts.js file.
- We start by importing the action types we are going to use:
import { CREATE_POST, EDIT_POST, DELETE_POST } from '../actionTypes'
- Then, we define the createPost action creator. It takes two arguments—the username and all data for the post:
export const createPost = (user, post) => {
- For the second argument, we are going to use destructuring to pull out the data we need. Using destructuring, we can also set a default value for the category. By default, the category will be set to 'random':
const { title, text, category = 'random' } = post
- We throw an error if the title or text are not set:
if (!title || !text) { throw new Error('invalid ...