Skip to content

Instantly share code, notes, and snippets.

@trueadm
Last active February 23, 2018 21:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trueadm/4a8b1cafd5d4e0405dc9885b4d7c94d3 to your computer and use it in GitHub Desktop.
Save trueadm/4a8b1cafd5d4e0405dc9885b4d7c94d3 to your computer and use it in GitHub Desktop.
// maybe we don't need to pass "click" as the first param, just passing in the config might be good enough
const handleClick = ReactDOM.createEvent("click", {
// imperative stuff is defined with config
preventDefault: true,
stopPropagation: true,
passive: false,
});
function reducer(e) {
// do reducer stuff
}
class MyComponent extend React.Component {
render() {
// reducer is a function pulled out here, but can easily be an arrow function to access props/state
return (
<button onClick={handleClick(reducer)}>Click me</button>
);
}
}
@acdlite
Copy link

acdlite commented Feb 23, 2018

Maybe ReactDOM.createEventHandler?

@acdlite
Copy link

acdlite commented Feb 23, 2018

I still don't like that the event object is passed to the reducer. I would like it more if you had to specify a mapping function of event => payload (I know @sebmarkbage doesn't like this idea).

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