이전 게시물 링크 입니다.
https://codingapple.com/forums/topic/react%ec%97%90%ec%84%9c-%eb%b3%80%ea%b2%bd%eb%90%9c-state%ea%b0%92-%ed%95%98%ec%9c%84-%ec%bb%b4%ed%8f%ac%eb%84%8c%ed%8a%b8%eb%a1%9c-%eb%84%98%ea%b2%a8%ec%a3%bc%eb%8a%94-%eb%b2%95/#post-66662
>>usestate변환 값 하위 컴포넌트에 반영 하는 법<<
강사님 말씀대로 하위컴포넌트의 변수를 setInterval밖으로 빼는데.. 흑 도저히 모르겠습니다.
export function MainApiCom(){ //부모 컴포넌트
let [this_isWait, setthis_isWait] = useState(0);
const variable ={
this_isWait
}
let [SendProps, setSendProps] = useState([
variable //0
,getStateInput //1
]);
function getStateInput(){
axiosFunction(a,b,c);
}
function ajaxFunction(a,b,c){
axios.then( //axios돌리고 결과값 state에 넣어줌
this_isWait = 1;
);
};
return (
<>
{WaitPage && <WaitDefault SendProps ={SendProps}/>}
</>
);
};
export function ChildCom(props){ //자식 컴포넌트
const rerend = 0;
useEffect(() => {
let iswait = props.SendProps[0].this_isWait;
let playAlert = setInterval(function() {
console.log("[playAlert]iswait : " +iswait);
if ( iswait == "T" ) {
props.SendProps[1]();
}
}, 1000);
return () => clearInterval(playAlert);
}, []);
return(<></>);
};