Skip to content

Instantly share code, notes, and snippets.

@jepras
Created October 19, 2018 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jepras/9451dd2f8d341b1e0bd8c88009200988 to your computer and use it in GitHub Desktop.
Save jepras/9451dd2f8d341b1e0bd8c88009200988 to your computer and use it in GitHub Desktop.
Basic Redux setup with store, actionCreator & reducer that adds to immutable array
// define ADD, addMessage(), messageReducer(), and store here:
const ADD = 'ADD';
const messageReducer = (state = [], action) => {
switch(action.type) {
case ADD:
return [
...state,
action.message
]
default:
return state;
}
};
const addMessage = (message) => {
return {
type: ADD,
message: message
};
};
const store = Redux.createStore(messageReducer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment