报错信息

TypeError: Super expression must either be null or a function, not undefined

解决

在学习React的时候,使用静态引入文件,起初会时不时的出现这个错,一般情况下,是 Component 的首写字母没有大写造成的!

class DefaultTitle extends React.Component {
  constructor(props) {
    super(props);
  }
  static defaultProps = {
    title: 'Hello React!',
  }
  render() {
    return <h4>{this.props.title}</h4>;
  }
}
ReactDOM.render(
  <DefaultTitle />,
  document.getElementById('root')
)