response.json()) .then((posts) => setPosts(posts)); }, []); "> response.json()) .then((posts) => setPosts(posts)); }, []); "> response.json()) .then((posts) => setPosts(posts)); }, []); ">
useEffect(() => {
fetch("<https://jsonplaceholder.typicode.com/posts>")
.then((response) => response.json())
.then((posts) => setPosts(posts));
}, []);
useEffect
를 사용할때 위처럼 두번째 인자로 빈 배열을 주지 않으면 무한 재랜더링이 일어난다.
이 두번째 인자의 역할과, 왜 무한루프가 일어나는지 알아봐야 한다.