Is it a good practise to use React Decorators?

878 views Asked by At

I am just curious which practice is better and more usable nowadays, is it cleaner to write decorators in React or not?

The example of difference below:

@reduxForm({form: 'exampleForm', onSubmit: formOnSubmit('example-from-action/')})
export default class ExampleForm extends React.Component {
  render() {
    return <div></div>
  }
}
    class ExampleForm extends React.Component {
        render() {
            return <div></div>
          }
    }

    export default reduxForm({form: 'exampleForm', onSubmit: formOnSubmit('example-from-action/')})(ExampleForm);

1

There are 1 answers

1
Axnyff On BEST ANSWER

In my opinion, for the moment, it's still a bad idea to use decorator in javascript.

They're still a stage 2 proposal: https://github.com/tc39/proposals.

According to this process https://tc39.es/process-document/, it does not mean it will surely be included in the language.

If you do use decorators, it will be probably with either typescript or babel ( legacy-decorators). You might have to change some code later to fix if the actual feature in the language does not match, or if it's rejected.