Decorators

Decorators (supported by Babel, in Stage 2 proposal as of 03/17)

If you’re using something like mobx, you can decorate your class components — which is the same as passing the component into a function.
Decorators are flexible and readable way of modifying component functionality.

Non-decorators approach

  1. class ProfileContainer extends Component {
  2. // Component code
  3. }
  4. export default observer(ProfileContainer)

With decorators

  1. @observer
  2. export default class ProfileContainer extends Component {
  3. // Component code
  4. }

Article:

  • @gigobyte/enhancing-react-components-with-decorators-441320e8606a">Enhancing React components with Decorators