Published on

React Errors

Authors
  • avatar
    Name
    Inhwan Cho
    Twitter
  1. [Error] TypeError: destroy is not a function TypeError: destroy is not a function useEffect 사용 시
// 이 코드로 실행 시 에러가 발생.
// return에 작성해서 에러가 발생
useEffect(()=> f());
// 아래 코드로 수정하면 해결 가능.
useEffect(() => {
	f();
});
  1. Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.

react에서는 async function을 호출 시 에러가 나서 아마 사용 할 방법이 있긴 할 것 같은데, 일단 useEffect를 사용하면 해결된다.

  1. [Error] A component suspended while responding to synchronous input. This will cause the UI to be replaced with a loading indicator. To fix, updates that suspend should be wrapped with startTransition.
import { lazy, Suspense } from "react";

// lazy사용 시 Suspanse로 감싸지 않아서 에러 발생
const Detail = lazy(() => import("./Detail.js"));

// 아래와 같이 해결
<Suspense fallback={<div>로딩 중 문구</div>}>
  <Detail />
</Suspense>