본문 바로가기
TIL/Javascript

React.js | TypeError: Cannot read property ‘replace’ of undefined

by 홍차23 2021. 1. 15.

TypeError: Cannot read property ‘replace’ of undefined

 

undefined인 객체에 replace 메소드를 호출해서 발생하는 에러다.

값을 받아온 이후에 실행되도록 if문을 추가해서 해결했다.

 

contentId = props.contentId

if(contentId) { // props 가 있다면
	contentId = contentId.replace() //replace() 메소드 실행
}

댓글