Hacker News new | past | comments | ask | show | jobs | submit login

Thanks for the well thought out response. Your second point about class definitions and ease of testing is making me reconsider my using decorators for HOC's.

To your first point, I would say the HOC's as decorators would be very easy to code mod as well. Just go to ever file with decorators on my components and rewrite it to use _.fp.pipe() or apply them longhand or whatever. It probably couldn't comfortably be done in an automated fashion but it would be straightforward and not require a lot of thought.

And to the third point I have never had those not work right when using connect. I would be interested in an example even if it's just a stack overflow question where it came up.

As a real quick example, purely off the top of my head:

    @connect(state => ({a : state.a})
    class MyComponent extends React.Component {}

    MyComponent.propTypes = {a : PropTypes.string.required, b : PropTypes.number.required}
    MyComponent.defaultProps = {b : 42}
In this example, both the propTypes and defaultProps definitions are being applied to the wrapper component, not the actual "plain" MyComponent class. So, while the required `b` prop might get satisfied almost accidentally from the defaultProps value, the required `a` prop won't exist on the wrapper, as the wrapper itself is extracting that value from the Redux state internally and passing it to the plain MyComponent.

I've definitely seen this pop up as a recurring question that's confused people.

Ah. That has never come up for me because I assign `propTypes` and `defaultProps` within the class definition using class properties. I had assumed you would be assuming I would too because you made mention of class properties in your post. Who would go to the trouble of setting up decorators without also using class properties syntax? Quite a few people, apparently, but the practice of using one and not the other baffles me.

Yeah, I actually wasn't 100% sure whether class properties + a decorator would play together as "expected". Thinking about it, I would guess they must, in which case defining those values as class properties also would be reasonable.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact