When to us ‘this’ in react components (non-exhaustive list)

Within the render() method you use this when:

  • accessing props: this.props.whatever
  • accessing states: this.state.whatever
  • accessing methods: this.method

Not used when:

  • variables:
let lemons = {color: 'yellow'};

lemons.color // we don't need the 'this'

Leave a comment

Design a site like this with WordPress.com
Get started