Next.js React SetInterval 시, 계속해서 해출하는 이슈 발생

나의 재물운? 연애운은?

AI가 봐주는 내 사주팔자 - 운세박사

https://aifortunedoctor.com/

Next.js React SetInterval 시, 계속해서 해출하는 이슈 발생

영리치 0 1,179 2023.01.04 10:14


리액트 컴포넌트 안에서 setInterval 호출하면 얘가 리액트 상태 변화 있을 때마다 계속 호출되어서 무한 호출됨

const updateSource = setInterval(async () => {
const geojson = await getLocation(updateSource);
// mapRef.current?.getSource("iss").setData(geojson);
}, 5000);


따라서 useEffect 안에 감싸서 한 번만 호출될 수 있도록 해야함

useEffect(() => {
const updateSource = setInterval(async () => {
const geojson = await getLocation(updateSource);
// mapRef.current?.getSource("iss").setData(geojson);
}, 5000);
}, []);


React setInterval 관련 무한 호출 이슈

Comments

나의 재물운? 연애운은?

AI가 봐주는 내 사주팔자 - 운세박사

https://aifortunedoctor.com/

Category
Magazine
훈남/훈녀
 
 
 
상점
Facebook Twitter GooglePlus KakaoStory NaverBand