티스토리 뷰
728x90
반응형
render(){
if(this.props.a != 'undefined' && this.props.a != null){
return (
<>
aa
</>
)
}
}
위와 같은 코드작성시 에러가난다
if 조건문에 맞으면 다행인데 맞지않으면 그려지지 않아서 에러가 발생
조건부 렌더링을 한다면 반드시
render(){
if(this.props.a != 'undefined' && this.props.a != null){
return (
<>
aa
</>
)
}else {
return (
<>
bb
</>
)
}
}
위와 같이 반드시 else처리로 빈 div값이라도 넘겨줘야 에러가 나지않는다
728x90
반응형
'Error > React.js' 카테고리의 다른 글
[React]The react-scripts package provided by Create React App requires a dependency: (0) | 2020.02.12 |
---|---|
[React] ...(isEnvProductionProfile && { ^^^ SyntaxError: Unexpected token ... (0) | 2020.02.06 |
[React] npm install, npm update (0) | 2020.01.11 |
[React] Cannot read property 'offsetWidth' of null or undefined (0) | 2020.01.08 |
[node.js] Error: setuid user id does not exist (0) | 2019.12.30 |
댓글