FrontEnd/React.js
[ React.js ] 에러 VM42:9 Uncaught TypeError: Super expression must either be null or a function, not undefined
SangHoonE
2021. 9. 1. 09:54
수정 21.09.01.10:11
에러해결 - ReactDOM.Component => React.Component
DOM이 아니라 그냥 React만 호출해야했다.
VM42:9 Uncaught TypeError: Super expression must either be null or a function, not undefined
React.js 하던와중 갑자기 이런 에러가 발생
왠지모르겠음..
super()를 선언할때 인자로 null 혹은 function이 들어가야하는데 undefined가 들어갔다. 라는 뜻 같은데..
props에 해당하는 부분이 undefined 된건가?
흠.
코드는 대충 클릭이벤트 함수를 생성한것인데, 이렇다.
<body>
<div id="root"></div>
<script type="text/babel">
class App extends ReactDOM.Component {
constructor (props) {
super(props)
this.state = {
count : 0
}
this.countUp = this.countUp.bind(this)
}
render () {
return (
<div>
<h1>클릭한 횟수 : {this.state.count}</h1>
<button onClick={this.countUp}>클릭</button>
</div>
)
}
countUp (event) {
this.setState({
count: this.state.count + 1
})
}
}
const container = document.querySelector("#root")
ReactDOM.render(<App />, container)
</script>
</body>
반응형