ES2015/2016 question: safe to use decorators?

I noticed that, at some point, decorators were removed from Babel and one now has to use a plugin to add support. Are decorators “safe” to use, currently, or are they at risk of being removed from the spec? I have situations where my higher-order components are getting out of hand, e.g.:

export default SomeThing()(OtherHOC(AnotherHOC()(MyComponent)))

Decorators are currently in stage 2, so in other words they’re in “Draft” status. That means some form of decorator support is eventually coming, but what that support looks like (and how it will be implemented) is still up in the air. If you don’t mind living on the edge a bit (and don’t mind refactoring your code to adapt to the changing spec), then by all means go for it! That being said, many companies (MDG included) prefer not to use any features below stage 3.

1 Like

That’s the thing though—and please correct me if I’m wrong—decorators are no longer in stage 2 in Babel 6. I have babel-presets-stage-1 installed, and I can’t use decorators without explicitly adding the transform-decorators-legacy package.

That word “legacy” is what worries me.

They’re still in stage 2 (that link is up to date). It’s just that Babel has disabled support as their implementation is now very different than the current proposal. For the full details see:

1 Like

Ahh, makes sense! Thanks for that. :slight_smile:

Some very popular libraries like react-dnd and mobx indeed use/offer/recommend decorators and I have a strong feeling once it receives a higher stage status, you will likely have little to no refactoring to do. They make the code easier on the eye and much more perceivable.

1 Like

Definitely! Once you get past 2 higher order functions wrapping your component, things get a little ugly.

2 Likes