Created
January 19, 2020 16:08
-
-
Save vcapretz/09c2f19643575982716c5b9a2ea840cf 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 { createAction, createReducer, configureStore } from '@reduxjs/toolkit' | |
const addTodo = createAction('ADD_TODO') | |
const toggleTodo = createAction('TOGGLE_TODO') | |
const todos = createReducer([], { | |
[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: todos }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment