简体   繁体   中英

React and ECMA6

I'm using ECMA6 classe and React, but running into a situation where exceptions in the render() method of a nested component don't get reported.

Any ideas?

For instance, this won't report an exception:

class Child extends React.Component {
  render() {
    foo; // Throws exception, "foo is undefined"
  }
}

class Demo extends React.Component {
  render() {
    return <Child />
  }
}

The function render need to return somethings. There is no return in your render function and foo needs to be declared somewhere.

class Child extends React.Component {
  render() {
    let foo = <span>HelloWorld</span>;
    return foo; // foo is now defined
  }
}

class Demo extends React.Component {
  render() {
    return <Child />
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM