GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Decorator is not supported! · Issue #214 · react/create-react-app

Decorator is not supported! #214

New issue
Copy link
New issue
Copy link
Closed
Closed
Decorator is not supported!#214
Copy link

Description

@HatemJerbi
HatemJerbi
opened on Jul 26, 2016
Issue body actions

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

Activity

  1. ForbesLindesay commented on Jul 26, 2016

    @ForbesLindesay
    ForbesLindesay
    on Jul 26, 2016
    Contributor
    More actions

    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
  2. eanplatter commented on Jul 26, 2016

    @eanplatter
    eanplatter
    on Jul 26, 2016
    Contributor
    More actions

    We are holding off decorators until babel supports them out of the box, for more info check out #107

  3. eanplatter
    closed this as completedon Jul 26, 2016
  4. gaearon commented on Jul 26, 2016

    @gaearon
    gaearon
    on Jul 26, 2016
    Contributor
    More actions

    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
  5. kevinejohn commented on Jul 29, 2016

    @kevinejohn
    kevinejohn
    on Jul 29, 2016
    More actions

    @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

  6. gaearon commented on Jul 29, 2016

    @gaearon
    gaearon
    on Jul 29, 2016
    Contributor
    More actions

    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
  7. kevinejohn commented on Jul 29, 2016

    @kevinejohn
    kevinejohn
    on Jul 29, 2016
    More actions

    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
  8. mxstbr commented on Jul 29, 2016

    @mxstbr
    mxstbr
    on Jul 29, 2016
    Contributor
    More actions

    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
  9. mweststrate commented on Sep 1, 2016

    @mweststrate
    mweststrate
    on Sep 1, 2016
    More actions

    For people stumbling into this in the future, here is a small create-react-app based repo with MobX, without decorators:

    https://github.com/mobxjs/create-react-app-mobx

    @mxstbr well, not removing, but make it very clear it is optional :)

    Reacted by Martin van Driel, kitze 🚀, AbeI Getachew, Jesvin Jose, web3li, Dana Woodman, Robin Wieruch, jpdorsy, Chris, Chang Yan and 1 more
  10. mweststrate commented on Sep 3, 2016

    @mweststrate
    mweststrate
    on Sep 3, 2016
    More actions

    The MobX docs now have a dedicated section listing how to use or avoid using decorators. I hope that helps avoid confusion in the future! http://mobxjs.github.io/mobx/best/decorators.html

    Reacted by kitze 🚀, Gregory Shekhet and Chang Yan
  11. mweststrate commented on Sep 26, 2016

    @mweststrate
    mweststrate
    on Sep 26, 2016
    More actions

    Didn't try yet, but this should allow using decorators with create-react-app without ejecting: https://www.npmjs.com/package/custom-react-scripts. Might be interesting to check out if anybody runs into this in the future.

    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
  12. jason-henriksen commented on Dec 29, 2016

    @jason-henriksen
    jason-henriksen
    on Dec 29, 2016
    More actions

    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
  13. tbillington commented on Dec 29, 2016

    @tbillington
    tbillington
    on Dec 29, 2016
    More actions

    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
  14. jason-henriksen commented on Dec 29, 2016

    @jason-henriksen
    jason-henriksen
    on Dec 29, 2016
    More actions

    @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.

  15. smmoosavi
    added a commit that references this issue on Mar 13, 2017

    add decorator example

    b2427a4
  16. mgallant23
    added a commit that references this issue on May 10, 2017

    Update README.md

    c5094ac
  17. gaearon commented on Aug 15, 2017

    @gaearon
    gaearon
    on Aug 15, 2017
    Contributor
    More actions

    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
  18. rclai commented on Aug 22, 2017

    @rclai
    rclai
    on Aug 22, 2017
    More actions

    According to that table at the top, it says that there's no breaking change, just a new feature.

  19. existentialism commented on Aug 23, 2017

    @existentialism
    existentialism
    on Aug 23, 2017
    Contributor
    More actions

    @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
  20. silouanwright commented on Oct 27, 2017

    @silouanwright
    silouanwright
    on Oct 27, 2017
    More actions

    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
  21. rclai commented on Oct 29, 2017

    @rclai
    rclai
    on Oct 29, 2017
    More actions

    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
  22. ilyaLibin commented on Jan 9, 2018

    @ilyaLibin
    ilyaLibin
    on Jan 9, 2018
    More actions

    Use this to inject mobx decorators into config without ejecting.
    https://github.com/timarney/react-app-rewired/tree/master/packages/react-app-rewire-mobx

  23. gaearon commented on Jan 9, 2018

    @gaearon
    gaearon
    on Jan 9, 2018
    Contributor
    More actions

    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.

  24. react
    locked and limited conversation to collaborators on Jan 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.