報錯信息
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')
)