Created
June 9, 2020 20:04
-
-
Save marshallmurphy/b7b84ff2cb62c3008eaab362e5a233f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/slices/recipes.js | |
import { createSlice } from '@reduxjs/toolkit' | |
export const initialState = { | |
loading: false, | |
hasErrors: false, | |
recipes: [], | |
} | |
// A slice for recipes with our 3 reducers | |
const recipesSlice = createSlice({ | |
name: 'recipes', | |
initialState, | |
reducers: { | |
getRecipes: state => { | |
state.loading = true | |
}, | |
getRecipesSuccess: (state, { payload }) => { | |
state.recipes = payload | |
state.loading = false | |
state.hasErrors = false | |
}, | |
getRecipesFailure: state => { | |
state.loading = false | |
state.hasErrors = true | |
}, | |
}, | |
}) | |
// The reducer | |
export default recipesSlice.reducer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment