akjfal

Unhandled Rejection(TypeError): Invalid attempt to destructure non-iterable instance 본문

react/react 에러

Unhandled Rejection(TypeError): Invalid attempt to destructure non-iterable instance

akjfal 2019. 11. 23. 11:42

하나의 변수를 다른 방식으로 중복되서 사용할 시 방생하는 에러다

import { testFunction } from './test'

export default function Main(){
  const { result1, result2 } = testFunction(); // 1번
  testFunction(1); // 2번
  return(
  ...
  )
}

const testFunction(num){
	useEffect(()=>{
    	console.log(num);
    },[])
}

위와 같이 testFunction은 단순히 인자만 넘기는 함수다.

하지만 result2개를 리턴하는 선언이 하나있고, 인자를 제대로 넘긴 함수 선언이 있다.

이랬을 때 위와 같은 에러가 발생한다.

잘못 선언 한 주석 1번을 지워주게 되면 에러가 사라지게된다.

Comments