Created
January 21, 2020 13:19
-
-
Save vcapretz/c6feae1823ad08f7103c07a0bfd2df02 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { createSlice, configureStore } from '@reduxjs/toolkit' | |
const todosSlice = createSlice({ | |
name: 'todos', | |
initialState: [], | |
reducers: { | |
addTodo(state, action) { | |
const { id, text } = action.payload | |
state.push({ id, text, completed: false }) | |
}, | |
toggleTodo(state, action) { | |
const todo = state.find(todo => todo.id === action.payload) | |
if (todo) { | |
todo.completed = !todo.completed | |
} | |
} | |
} | |
}) | |
const store = configureStore({ reducer: todosSlice.reducer }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment