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

home2 게시판 React 게시판 인풋 글자 입력하면 왜 하얀화면이 나오는지 모르겠습니다.

인풋 글자 입력하면 왜 하얀화면이 나오는지 모르겠습니다.

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

    남도일
    참가자
    import { useEffect } from "react";
    import { useParams } from "react-router-dom";
    import styled from 'styled-components'
    import { useState } from "react";
    // let YellowBtn = styled.button`
    // background : ${props => props.bg};
    // color : ${props => props.bg == 'blue' ? 'white' : 'black'};
    // padding : 10px;
    // `
    /* eslint-disable jsx-a11y/alt-text */
    function Detail(props) {
    //useEffect 쓰는 이유 
    //먼저 useEffect안에 있는 코드는 html렌더링 후에 동작
    let [count , setCount] = useState(0)
    let [ alert, setAlert ] = useState(true);
    let [ num , setNum] = useState('')
    useEffect(()=>{
    let timer = setTimeout(()=>{ setAlert(false) }, 2000);
    console.log(2)
    return ()=>{
    console.log(1)
    clearTimeout(timer)
     }
     },[]);
    // useEffect(()=>{}) 1. 재랜더링마다 코드실행하고 싶으면
    // useEffect(()=>{}, []) 2.mount시 1회 코드실행하고 싶으면
    // useEffect(()=>{
    // return () =>{ 3.unmount시 1회 코드실행하고 싶으면
    // }
    // },[])
    useEffect(()=>{
    if (isNaN(num) === true){
    alert('그러지마세요')
     }
     }, [num])
     
    let {id}=useParams();
    let product = props.shoes.find(function(x){
    return x.id == id
    });
    return (
    <div className="container">
    {
    alert === true
     ? (<div className="alert alert-warning">
    <p>2초 이내 구매시 할인</p>
    </div>)
     : null
    }
    {count}
    {/* <YellowBtn bg="blue">버튼</YellowBtn> */}
    <button onClick={()=>{ setCount(count+1) }}>버튼</button>
     
    <div className="row">
    <div className="col-md-6">
    <img src="">
    </div>
    <div className="col-md-6">
    <input onChange={(e) => setNum(e.target.value)}></input>
    <h4 className="pt-5">{props.shoes[id].title}</h4>
    <p>{product.content}</p>
    <p>{product.price}원</p>
    <button className="btn btn-danger">주문하기</button>
     
    </div>
    </div>
    </div>
     
     )
    }
    export default Detail;
    #45776

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

    남도일
    참가자
    TypeError: alert is not a function. (In 'alert('숫자만입력')', 'alert' is true) 
    이렇게 뜹니다
    #45885

    codingapple
    키 마스터
    alert라는 변수명을 다른걸로 바꿉시다
4 글 보임 - 1 에서 4 까지 (총 4 중에서)
  • 답변은 로그인 후 가능합니다.

About

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

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

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