Warning: Functions are not valid as a React child.

Hyunwoo Seo·2022년 7월 10일
0

ErrorCode

목록 보기
12/16
post-thumbnail

Warning: Functions are not valid as a React child.

Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.    
  • 함수인데 실행 안하고 render 부분에 코딩한 경우이다.
  • 함수 코드를 render에 넣었으니 당연히 정상적인 실행이 안됨...
const Example = () => {
  const testFunc = () => {
    return 'test return value.';
  };
  return <span>{testFunc}</span>;
};    
  • 위처럼 특정 함수를 만들고 render 부분에서 실행 안하고 함수만 호출시 위 같은 에러가 뜬다.
  • 해결방법은 함수 실행해주면 된다.
const Example = () => {
  const testFunc = () => {
    return 'test return value.';
  };
  return <span>{bookingStateTime()}</span>;
};
 

0개의 댓글