Skip to content

Instantly share code, notes, and snippets.

@JeromeFranco
Last active April 5, 2019 12:45
Show Gist options
  • Save JeromeFranco/d100124fa421fb8ca7093804fc88d2f3 to your computer and use it in GitHub Desktop.
Save JeromeFranco/d100124fa421fb8ca7093804fc88d2f3 to your computer and use it in GitHub Desktop.
// todo-actions.js
import { createAction } from 'redux-starter-kit';
// Create an action creator
export const addTodo = createAction('TODO/ADD_TODO');
// todo-reducers.js
import { addTodo } from './todo-actions';
export function todosReducer(state = [], action) {
switch(action.type) {
// Use the action creator's type property to handle action
case addTodo.type:
return state.concat(action.payload);
default:
return state;
}
}
// todo-sagas.js
import { addTodo } from './todo-actions';
function* addTodoSaga({ payload }) {
// Some side effects
}
// Use the action creator's type property to handle action
export default takeLatest(addTodo.type, addTodoSaga);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment