Skip to content

Instantly share code, notes, and snippets.

@chrisui
Last active September 21, 2016 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisui/d0d1e1b0820ada119805d44f89914c32 to your computer and use it in GitHub Desktop.
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?
export function Component({state, increment}) {
return (
<div>
{state.count} hits!
<button onClick={increment}>Hit me!</button>
</div>
);
}
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
const increment = state => ({...state, count: state.count + 1});
@withProxiedState('state', {count: 0}, {increment})
Component
@chrisui
Copy link
Author

chrisui commented Sep 12, 2016

Where "actions" are tied to a single "reducer"/"store" the ceremony of further indirection (dispatched action types) could be considered redundant.

@chrisui
Copy link
Author

chrisui commented Sep 21, 2016

(Ignore terrible name withProxiedState)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment