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

報錯信息

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')
)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章