React 오류

sam_il·2022년 8월 11일

함수를 실행하지 않고 호출만 했을 때 발생하는 오류

❗ Warning: Functions are not valid as a React child. This may happen if you return a Component instead of from render. Or maybe you meant to call this function rather than return it.

const Example=()=>{
	...
}

return(
	<span>{Example}</span>
);

위의 코드처럼 특정 함수를 만들고 render 부분에서 실행 안하고 함수만 호출시 위 같은 에러가 뜬다.
해결방법은 함수를 실행해주면 된다.

const Example=()=>{
	...
}

return(
	<span>{Example()}</span>
);

map 함수 사용 시 오류

❗ Expected an assignment or funcion call and instead saw and expression no-unused-expressions

중괄호, 소괄호 사용 주의 필요

  1. map 함수에서 {} (중괄호) 사용 시 return 필요

  2. map 함수에서 요소를 () (소괄호)에 담아서 사용


📌 참고자료

에러1
https://kyounghwan01.github.io/blog/dev-report/2020/20_08/#_8%E1%84%8B%E1%85%AF%E1%86%AF-%E1%84%8B%E1%85%B5%E1%84%89%E1%85%B2-%E1%84%8B%E1%85%AD%E1%84%8B%E1%85%A3%E1%86%A8

에러2
https://helicopter55.tistory.com/2

profile
🍀

0개의 댓글