Skip to content

Instantly share code, notes, and snippets.

@vcapretz
Created January 21, 2020 13:19
Show Gist options
  • Save vcapretz/c6feae1823ad08f7103c07a0bfd2df02 to your computer and use it in GitHub Desktop.
Save vcapretz/c6feae1823ad08f7103c07a0bfd2df02 to your computer and use it in GitHub Desktop.
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