functional-react icon indicating copy to clipboard operation
functional-react copied to clipboard

event isn't exposed in handler

Open jschr opened this issue 9 years ago • 2 comments

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.

jschr avatar Jun 08 '15 14:06 jschr

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.

aickin avatar Jun 09 '15 17:06 aickin

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.

jschr avatar Jun 09 '15 17:06 jschr