Last active
September 1, 2017 02:21
-
-
Save rupeshtiwari/49c76bb8c930bdbc2088c109007c5039 to your computer and use it in GitHub Desktop.
Redux Store Example
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
// Code goes here | |
const { | |
createStore | |
} = Redux; | |
const initialState = { | |
name: 'Rupesh' | |
}; | |
function reducer(state = initialState, action = {}) { | |
switch (action.type) { | |
case 'change': | |
{ | |
return Object.assign({}, state, { | |
name: action.payload | |
}); | |
} | |
default: | |
return state; | |
} | |
} | |
const store = createStore(reducer); | |
console.log('state before', store.getState()); | |
store.dispatch({ | |
type: 'change', | |
payload: 'Ritesh' | |
}); | |
console.log('state after', store.getState()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment