GeezerVison is showing github.com — Decorator is not supported! · Issue #214 · react/create-react-app
Decorator is not supported! #214Description
Note from maintainers
For people coming to this thread later—if you use MobX or a similar library, you don’t need decorators. They are just syntax sugar in this case.
Learn more: #214 (comment), #411 (comment).
Here is why we don’t include them: #411 (comment).
we can not use library like mobx (@observer,@observable).
to fix this :
- babel stage-1
- babel "transform-decorators-legacy" plugin
Reacted by Yevheniia Rakhmatova, Jonas Oppenlaender, Alexander Kozhevin, Jon, Etienne Crombez, Travis Fischer, David Novák, Elad Ossadon, limichange, Maxim and 9 more ActivityForbesLindesay commented on Jul 26, 2016 Decorators are still in the very early stages of standardisation. The behaviour of them could change rapidly, without warning. Users of decorators need to be willing to adapt fast, and therefore aren't the main target for create-react-app. I don't think we should be including them in this project at this time.
I do think we should look into supporting customisation of the babel, eslint and webpack configs in some way, but that's a larger discussion. Reacted by henry, James Prado, fred, Peeyush Kushwaha, Chris and Samuel Kendrick Reacted by Jonas Oppenlaender, Ge Yang, Harold Waterkeyn, Mohammad Bagher Ehtemam, Salon.sai, 乔, Kip Obenauf, Guilherme Gotardo, Nachiket Patel, Mark and 1 more eanplatter commented on Jul 26, 2016 We are holding off decorators until babel supports them out of the box, for more info check out #107 gaearon commented on Jul 26, 2016 You can use MobX without decorators. Reacted by Max Stoiber, kitze 🚀, Lewis Yuburi, B. Cedric Cogell, Chema, Ricardo Berdejo, Khalil Zaidoun, Juwan Wheatley, Sebastián Galiano, henry and 6 more Reacted by Evgeniy Kucheruk, Joe Narvaez, AnYu_HAPPY, ouyang-chao, Mikhail S. Pabalavets, Alex Panov, Patrik Krupar, Kip Obenauf, xxxcc, Ivan Popov and 41 more Reacted by Filip Hoško kevinejohn commented on Jul 29, 2016 @gaearon Don't you have to use the old React.createClass method if you do not use decorators though? It changes a lot of the code structure in your components (No constructor(), commas after every method, etc...) :-/
Would be great to be able to use create-react-app without ejecting to set babel decorator support.
var MyComponent = observer(React.createClass({ ...
https://mobxjs.github.io/mobx/best/syntax.html gaearon commented on Jul 29, 2016 No, you can do this just fine:
const MyComponent = observer(class MyComponent extends React.Component {
render() {
// Warning: don't use {this.onButtonClick.bind(this)} or {() => this.onButtonClick} !
return <button onClick={this.onButtonClick}>Hi</button>
}
onButtonClick = (e) => {
// bound function
}
})Reacted by Ogun Reacted by mlesk, AbeI Getachew, Lewis Yuburi, jsalonen, Gregory Shekhet, Ryder Xie, sameera, Zhe Chen, Jon, Andrew Philpott and 10 more Reacted by Khalil Zaidoun, Ali Torki, Evgeni Nikolov, Dean Sofer, Tarik Fojnica, Jamie Halvorson, Nick Sarafa, Ashutosh Das, Daniel Johansson, zhiyingzhou and 6 more Reacted by Lukas Bombach and Chang Yan kevinejohn commented on Jul 29, 2016 That works. Thank you!
I'm really surprised the mobx documentation never mentions this solution considering decorators are still experimental and not enabled by default in babel. I'll have to send them a pull request. Reacted by dan, AbeI Getachew, mayowa, sameera, Zhe Chen, Antti Pihlaja, Tomas Tichy, Chris, Yordis Prieto and Chris mxstbr commented on Jul 29, 2016 cc @mweststrate, I talked to him about this when we met at RuhrJS and he said he planned to remove the decorator syntax from the docs! Reacted by KJ, msaron and Michael Falck Wedelgård Reacted by Ogun mweststrate commented on Sep 1, 2016 Reacted by Martin van Driel, kitze 🚀, AbeI Getachew, Jesvin Jose, web3li, Dana Woodman, Robin Wieruch, jpdorsy, Chris, Chang Yan and 1 more mweststrate commented on Sep 3, 2016 Reacted by kitze 🚀, Gregory Shekhet and Chang Yan mweststrate commented on Sep 26, 2016 Reacted by Ollie Relph, twig, Gregory Shekhet, Lewis Blackwood, Sebastian Wilzbach, Joni Weiss, Sanket Sahu, Khalil Zaidoun, Lukas, Philipp Kief and 17 more Reacted by Rigo B Castro, Pedro Moreira, Nick Sarafa, Luis Santiago, Chris and Chang Yan jason-henriksen commented on Dec 29, 2016 I ended up ejecting to get decorators.
I'm primarily a c#/java dev, so I just don't understand how decorators can be at all controversial.
I mean Java got annotations over a decade ago. As an industry we've got a pretty clear understanding of good syntax and how they should work. It's just one more frustration for people who are used to a mature development language coming back into the wild wild west of JavaScript.
Not your fault, but come on. How can this this still be a controversy? Coming back to JavaScript from C# has turned me into an old man who says "Back in my day we had !" all the time. Reacted by Cristian Rosescu, Jinhyeok Lee, Matt McCray, Dave Handy, Nick Sarafa, Chris, Yeyo, Jacob, Pawel Paczuski, Evgeniy Kucheruk and 8 more Reacted by Eugene Zaretskiy, Andrei Rosca, Konstantin Pschera, Miklos Megyes, Nick Sarafa, Han You, Jon Koops, Antti Pihlaja and Brandon Phillips Reacted by talsibony and Jose Gomez tbillington commented on Dec 29, 2016 A better place to discuss it @jason-henriksen would be here where decorators are being discussed upstream (babel). Until they're standardised and supported officially they probably won't be in an "official"/"endorsed" project like create-react-app for obvious reasons. Reacted by Oscar Balladares M. and Jingtao Wang jason-henriksen commented on Dec 29, 2016 @mweststrate thanks for the comment on using custom-react-scripts. It made my eject effort unnecessary and was MUCH nicer to use than fiddling with things myself.
@tbillington thanks for the pointer to the discussion. I'm sure a noob like myself can't all that much help, but maybe there's some small way I can push that ball along. In the mean time, I'm happy with the plug-in of the legacy code that lets me get things done. Thanks again for the tip. gaearon commented on Aug 15, 2017 For anyone reading this in the future, I would like to point out that the decorators spec has changed significantly. I'm really glad we made the decision to not support them at early stage, so users who didn't eject don't need to change their code.
I don't recommend anyone to rely on the legacy decorator transform (that is not part of CRA). See this thread for more info: https://twitter.com/dan_abramov/status/897491076537356288. Reacted by GodofKim, ean, seungha-kim, Ge Yang and Terminalqo Reacted by Michał Matyas, Danyal Aytekin, Evgeniy Kucheruk and Ilya Reacted by ean and AlfredLabs-Hector rclai commented on Aug 22, 2017 existentialism commented on Aug 23, 2017 @rclai it's a bit misleading: it's not breaking in Babel's context because the linked PR is adding a totally new transform that relies on a completely different parser plugin (decorators2) than the "current" one.
The two syntaxes, as @gaearon mentioned, are definitely different, namely:
@bar
export default Foo {}
now needs to be:
export default
@bar class Foo { }
One of our "ship-Babel-7" tasks is to provide codemods for these types of changes to help ease the transition. Reacted by Richard, Peeyush Kushwaha, Ben Budnevich, Oleg Lustenko, Gaurav, Kip Obenauf, Misha Khazov and Iddan Aaronsohn silouanwright commented on Oct 27, 2017 Just to help anyone out: if you need to use inject with observable (without decorators) you can use it like this:
class Foo extends Component {
/* whatever view logic here */
}
Foo = inject('key')(obserable(Foo));
Reacted by Bayu and Søren Høyer rclai commented on Oct 29, 2017 Yes or you could use recompose's compose function to make it look nicer:
class Foo extends Component {
/* whatever view logic here */
}
export default compose(
inject('key'),
observable
)(Foo);
Reacted by seungha-kim, Lukas Bombach and pugson ilyaLibin commented on Jan 9, 2018 gaearon commented on Jan 9, 2018 It’s not supported and will break. If you’re okay with this, cool, but please don’t teach beginners to use something that will be broken in a year.
Furthermore, the legacy decorator plugin does not even support the latest specification and your code will likely break when you update it to the recent one (which isn’t implemented by Babel at all).
I’m locking this issue. As noted above, decorators are an unstable proposal and won’t be enabled until they both advance further and there is a Babel plugin that implements the latest spec.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|