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

home2 게시판 React 게시판 선생님 .. 갑자기 에러가 나는데여 ...

선생님 .. 갑자기 에러가 나는데여 ...

  • 이 주제에는 1개 답변, 2명 참여가 있으며 codingapple2 년 전에 전에 마지막으로 업데이트했습니다.
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #93120

    박지윤
    참가자
    # DetailPage
    
    
    
    import React, { useEffect, useState } from 'react'
    import { Container, Col, Row, Button } from 'react-bootstrap'
    import { useParams } from 'react-router-dom'
    import styled from 'styled-components'
    import { useDispatch } from 'react-redux'
    import { addItem } from '../store'
    let Discount = styled.div`
    background-color: #ffff00b9;
    `
    const DetailPage = (props) => {
    let [discount, setDiscount] = useState(true)
    let [num, setNum] = useState('')
    let dispatch = useDispatch();
    useEffect(()=>{
    let time = setTimeout( ()=>{ setDiscount(false) }, 2000)
    return ()=>{
    clearTimeout(time)
     }
     }, [])
    useEffect(()=>{
    if(isNaN(num) == true){
    alert("숫자만 !")
     }
     },[num])
    let {id} = useParams();
    let findItem = props.shoes.filter((x)=> x.id === id);
    console.log("finditem",findItem[0].title)
     
    return (
    <div>
    <Container className='detail-container'>
    {
    alert == true ? 
    <Discount>2초 이내 구매시 할인</Discount>
     : null
    }
    <Row>
    <Col className='img-detail'>
    < img src={props.img[id]} alt="detail img" />
    </Col>
    <Col className='buy-detail'>
    <input onChange={(event)=>{setNum(event.target.value)}} />
    <h4 style={{margin:'50px'}}>{findItem[0].title}</h4>
    <p style={{margin:'50px'}}>{findItem[0].price}</p>
    <Button variant="danger" className='btn-detail' onClick={()=>{
    dispatch(addItem({id:2, name:'BUFFALO CLD CORIN GRADIENT SNEAKER', count:4},))
     }}>Buy</Button>{' '}
    </Col>
    </Row>
    </Container>
    </div>
     )
    }
    export default DetailPage
    
    --------------------------------
    
    위 내용으로 코드를 전에 썻을 때는 잘 나왔는데 갑자기 에러가 떠요 
    
    스크린샷 2023-08-02 오전 12.27.50
    --------------------
    # MainPage
    
    
    
    <div>
    <div className='main-bg'></div>
    <div className='all-card'>
    <Container>
    <Row>
    {
    props.shoes.map((a, i)=>{
    return(
    <Col sm={3}>
    <Card shoes={props.shoes[i]} i={i+1}/>
    </Col>
     )
     })
    }
    </Row>
    </Container>
    <button onClick={()=>{
    axios.get('https://codingapple1.github.io/shop/data2.json')
     .then((result)=>{
    let copy = [...props.shoes, ...result.data]
    console.log(copy)
    props.setShoes(copy)
     })
     .catch(()=>{
    console.log("실패 ㅜㅜ")
     })
     }}>버튼</button>
    </div>
    </div>
     )
    }
    export default MainPage
    
    
    메인 페이지에서는 이렇게 썻는데 에러가 왜 나는건지 이유를 모르겠어요
    
    
    
    
    
    #93236

    codingapple
    키 마스터
    DetailPage로 props 잘 보냈나 확인해보고 .title 왼쪽에 있는거 있나 출력해봅시다
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 호 / 개인정보관리자 : 박종흠