Created
October 19, 2018 12:28
-
-
Save jepras/9451dd2f8d341b1e0bd8c88009200988 to your computer and use it in GitHub Desktop.
Basic Redux setup with store, actionCreator & reducer that adds to immutable array
This file contains 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
// 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