functional-react
functional-react copied to clipboard
event isn't exposed in handler
Hey great little library! I've been implementing some of these ideas into my own project with some slight changes. One of my favourite things so far is being able to deconstruct props/state with default values instead of needing to use getDefaultProps
:
export default component(({ props: { count: 0 } }) => {
return <div>{count}</div>;
});
However I did notice that in your handler wrapper that the original event isn't passed through:
https://github.com/aickin/functional-react/blob/master/index.js#L26
I ended up changing the handler wrapper to pass in e as the 2nd argument but I thought it would be worth mentioning.
I like the idea of destructuring default values into the props; really clever!
You're right that the original event needs to be passed through. I'll do that in the next version.
Thanks! I must say that using this functional wrapper has been a breath of fresh air over relying on this
. I'm curious to why you opted for only passing props/state as an object rather every dependency as a object that can be deconstructed in every function?
const render = ({ props, handler }) => { ... }
const shouldComponentUpdate = ({ props, nextProps }) => { ... }
const componentWillMount = ({ state, setState }) => { ... }
as opposed to
const render = ({ props }, handler }) => { ... }
const shouldComponentUpdate = ({ props }, { props: nextProps }) => { ... }
const componentWillMount = ({ state }, setState) => { ... }
Is the former a bad idea? Right now I'm torn between the two methods.