Skip to content

Instantly share code, notes, and snippets.

@gminova
Created November 25, 2019 17:50
Show Gist options
  • Save gminova/c0b32f7fe9982437d4e3aea495a43709 to your computer and use it in GitHub Desktop.
Save gminova/c0b32f7fe9982437d4e3aea495a43709 to your computer and use it in GitHub Desktop.

Revisions

  1. gminova created this gist Nov 25, 2019.
    27 changes: 27 additions & 0 deletions toDoReduxApp.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    const ADD_TO_DO = 'ADD_TO_DO';

    // A list of strings representing tasks to do:
    const todos = [
    'Go to the store',
    'Clean the house',
    'Cook dinner',
    'Learn to code',
    ];

    const immutableReducer = (state = todos, action) => {
    switch(action.type) {
    case ADD_TO_DO:
    return [...todos, action.todo]
    default:
    return state;
    }
    };

    const addToDo = (todo) => {
    return {
    type: ADD_TO_DO,
    todo
    }
    }

    const store = Redux.createStore(immutableReducer);