useEffect의 클린업 함수에서 arrow function expected no return value 린트 오류

cho·2024년 10월 25일

💥 트러블 슈팅

목록 보기
1/11
post-thumbnail

useEffect의 cleanup 함수에 있는 return 문에 화살표 함수는 return value가 있으면 안된다고 린트 오류가 뜬다. 이는 아래와 같이 if 문에 return undefined를 추가하면 해결이 된다.

    React.useEffect(() => {
      if (!api) {
        return undefined;
      }

      onSelect(api);
      api.on("reInit", onSelect);
      api.on("select", onSelect);
      return () => {
        api?.off("select", onSelect);
      };
    }, [api, onSelect]);

출처: https://stackoverflow.com/questions/67658900/arrow-function-expected-no-return-value-with-clean-up-function-in-useeffect

0개의 댓글