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

home2 게시판 React 게시판 input alert 오류

input alert 오류

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

    김도훈
    참가자
    숙제를 진행하고 input 칸에 문자를 넣으면 alert창이 떠야 하는데 화면이 다 사라지면서 백지상태가 됩니다 
    어떤 부분이 문제일까요 ㅠㅠ
    
    
    import { useEffect, useState } from "react";
    import { useParams } from "react-router-dom";
    function Detail(props) {
    let [count, setCount] = useState(0);
    let [alert, setAlert] = useState(true);
    let [num,setNum] = useState('');
    useEffect(() => {
    let a = setTimeout(() => {
    setAlert(false)
     },2000);
    return () => {
    clearTimeout(a);
     }
     }, [])
    useEffect(()=>{
    if (isNaN(num) == true){
    alert('숫자를 입력하세요')
     }
     }, [num])
     
    let {id} = useParams();
    let 찾은상품 = props.shoes.find(x => x.id == id);
    return (
    <div className="container">
    { alert == true
    ? <div className="alert alert-warning">
     2초이내 구매시 할인
     </div> : null }
     <button onClick={() => {
    setCount(count+1)
     }}>버튼</button>
     <div className="row">
     <div className="col-md-6">
     
     </div>
     <div className="col-md-6">
     <input onChange={(e)=>{ setNum(e.target.value)}} />
     <h4 className="pt-5">{찾은상품.title}</h4>
     <p>{찾은상품.content}</p>
     <p>{찾은상품.price}원</p>
     <button className="btn btn-danger">주문하기</button>
     </div>
     </div>
     </div>
     )
    }
    export default Detail;
    #43924

    codingapple
    키 마스터
    크롬 콘솔창엔 무엇이 뜹니까
    #44066

    김도훈
    참가자
    콘솔창에 따로 뜨는 것은 없고 오류만 뜹니다 ㅠㅠ
    기존에는 강의 중 말씀하신 Warning만 뜨다가 input에 문자를 넣으면
    
    react-dom.development.js:18687 The above error occurred in the <Detail> component:
        at Detail (http://localhost:3000/static/js/bundle.js:765:74)
        at Routes (http://localhost:3000/static/js/bundle.js:46886:5)
        at div
        at App (http://localhost:3000/static/js/bundle.js:48:74)
        at Router (http://localhost:3000/static/js/bundle.js:46819:15)
        at BrowserRouter (http://localhost:3000/static/js/bundle.js:45628:5)
    Consider adding an error boundary to your tree to customize error handling behavior.
    Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.
    
    이런 오류가 발생합니다
    #44083

    codingapple
    키 마스터
    에러메세지는 아마 그거 위에 있을듯요 
    let [alert, setAlert] 에서 alert라는 변수명을 다른걸로 바꿔서 씁시다 
    
    #44088

    김도훈
    참가자
    변수 바꾸니 해결 됐습니다 ㅠㅠ
    혹시 변수 alert가 의미가 있는 이름이라서 오류가 난 걸까요??
    #44123

    codingapple
    키 마스터
    네 alert같은 이름들은 쓰지맙시다
6 글 보임 - 1 에서 6 까지 (총 6 중에서)
  • 답변은 로그인 후 가능합니다.

About

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

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

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