Last active
September 21, 2016 13:37
-
-
Save chrisui/d0d1e1b0820ada119805d44f89914c32 to your computer and use it in GitHub Desktop.
Perhaps full reducer/actions are overkill for 90% of our component state needs?
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
export function Component({state, increment}) { | |
return ( | |
<div> | |
{state.count} hits! | |
<button onClick={increment}>Hit me!</button> | |
</div> | |
); | |
} |
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
const A_INCREMENT = 'A_INCREMENT'; | |
function reducer(state, action) { | |
switch(action.type) { | |
case A_INCREMENT: | |
return {...state, count: state.count + 1}; | |
default: | |
return state; | |
} | |
} | |
@withReducer('state', 'dispatch', reducer, {count: 0}) | |
@mapProps(props => ({ | |
increment: () => props.dispatch({type: A_INCREMENT}), | |
...props | |
})) | |
Component |
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
const increment = state => ({...state, count: state.count + 1}); | |
@withProxiedState('state', {count: 0}, {increment}) | |
Component |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(Ignore terrible name
withProxiedState
)