-
Notifications
You must be signed in to change notification settings - Fork 0
/
Redux-SendActionDataToStore
29 lines (24 loc) · 899 Bytes
/
Redux-SendActionDataToStore
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// this is a common practice i think to make the object property values immutable
const ADD_NOTE = 'ADD_NOTE';
// only function of the reducer method is to change state based on an action.
const notesReducer = (state = 'Initial State', action) => {
switch(action.type) {
// change code below this line
case ADD_NOTE:
return state= action.text;
// change code above this line
default:
return state;
}
};
// action creator which returns an object with at least a TYPE property and in this case also a note property
const addNoteText = (note) => {
// change code below this line
return {type: ADD_NOTE, text:note}
// change code above this line
};
// const in order to create the redux store for the application.
const store = Redux.createStore(notesReducer);
console.log(store.getState());
store.dispatch(addNoteText('Hello!'));
console.log(store.getState());