6 글 보임 - 1 에서 6 까지 (총 6 중에서)
-
글쓴이글
-
2022년 8월 24일 17:38 #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;
2022년 8월 25일 14:44 #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. 이런 오류가 발생합니다
2022년 8월 25일 15:57 #44083
codingapple키 마스터에러메세지는 아마 그거 위에 있을듯요 let [alert, setAlert] 에서 alert라는 변수명을 다른걸로 바꿔서 씁시다
-
글쓴이글
6 글 보임 - 1 에서 6 까지 (총 6 중에서)
- 답변은 로그인 후 가능합니다.