• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 React 게시판 react에서 변경된 state값 하위 컴포넌트로 넘겨주는 법 재질문

react에서 변경된 state값 하위 컴포넌트로 넘겨주는 법 재질문

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #66706

    박나연
    참가자
    이전 게시물 링크 입니다.
    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(<></>);
    };
    
    
    
    #66726

    codingapple
    키 마스터
    부모가 보낸 데이터 잘 들어있나 props부터 출력해봅시다
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠