Skip to content

Instantly share code, notes, and snippets.

@rupeshtiwari
Last active September 1, 2017 02:21
Show Gist options
  • Save rupeshtiwari/49c76bb8c930bdbc2088c109007c5039 to your computer and use it in GitHub Desktop.
Save rupeshtiwari/49c76bb8c930bdbc2088c109007c5039 to your computer and use it in GitHub Desktop.
Redux Store Example
// 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