1

I'm using ES6 to define methods in a React component.

class RootContainer extends Component {
  componentWillMount() {
    window.addEventListener('resize', this.handleWindowSizeChange)
  }

  componentWillUnmount() {
    window.removeEventListener('resize', this.handleWindowSizeChange)
  }

  handleWindowSizeChange = () => {
    this.props.update_width(window.innerWidth)
  }
  [...]

I'm mostly using the ES6 syntax so that I don't have to bind my method in my constructor. This code works just fine, unfortunately, whenever I try to build my app, I get a nice handleWindowSizeChange is not defined - no undef

How am I supposed to define it ?

Pierre Olivier Tran
  • 1,669
  • 4
  • 24
  • 40

0 Answers0