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

home2 게시판 React 게시판 장바구니 기능 만들기

장바구니 기능 만들기

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

    이도아
    참가자

    <h1><오류내용></h1>
     

    TypeError: history.push is not a function
    onClick
    C:/Users/나/Desktop/코딩애플/리액트수업/shop/src/App.js:125
    122 | let history = useHistory;
    123 |
    124 | return(
    > 125 | <div className="col-md-4" onClick={()=>{ history.push('/detail/'+ props.shoes.id) }}>
    | ^ 126 | <img src={'https://codingapple1.github.io/shop/shoes' + (props.a + 1) +'.jpg'} width="100%"></img>
    127 | <h4>{props.shoes.title}</h4>
    128 | <p>{props.shoes.content}&{props.shoes.price}</p>
    View compiled
    ▶ 19 stack frames were collapsed.
    This screen is visible only in development. It will not appear if the app crashes in production.
    Open your browser’s developer console to further inspect this error. Click the 'X' or hit ESC to dismiss this message.

     

     
    <h1><코드></h1>
    <strong>(부모 컴포넌트)</strong>

    <div className="container">

      <재고context.Provider value={재고}>

    <div className="row">
      {
      shoes.map(function(i,a){
        return <Gift shoes={shoes[a]} a={a}/>
      })

      }
    </div>
    </재고context.Provider>

     

     

    <strong>(자식컴포넌트)</strong>

    function Gift(props){

      let 재고 = useContext(재고context);
      let history = useHistory;

      return(
        <div className="col-md-4" onClick={()=>{ history.push('/detail/'+ props.shoes.id) }}>
          <img src={'https://codingapple1.github.io/shop/shoes' + (props.a + 1) +'.jpg'} width="100%"></img>
          <h4>{props.shoes.title}</h4>
          <p>{props.shoes.content}&{props.shoes.price}</p>
          <p>{재고[props.a]}</p>
        </div>
      )
    }

     

     

    강의 그대로 따라 쳤는데, 메인에서 상품 이미지 클릭 했을 때 저런 오류가 뜨네요.

    어떻게 해야 할까요..?

    #9655

    codingapple
    키 마스터

     let history = useHistory() 이래야할듯요

    #9658

    이도아
    참가자

    넵 감사합니다

3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 답변은 로그인 후 가능합니다.

About

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

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

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