Last active
February 23, 2018 21:36
-
-
Save trueadm/4a8b1cafd5d4e0405dc9885b4d7c94d3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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> | |
); | |
} | |
} | |
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
Maybe
ReactDOM.createEventHandler
?