input(2)
-
React 여러 input값 한개의 useState로 관리 하기 (객체 형태)
https://crispypotato.tistory.com/149 지난번은 input이 하나였지만 input값이 여러개인 상황에서도 useState하나만 사용 할 수 있다. 실제 코드 import React, { useState } from 'react'; function Input() { const [text, setText] = useState({ name:'', age:'' }) const {name, age} = text const change = (e) => { const {value,name} = e.target setText({ ...text, [name]: value }) } const reset = () => { setText({ name:'', age:'' }) } return ( 초기..
2021.11.20 -
React useState에서 input 값 관리
https://crispypotato.tistory.com/148 처럼 태그에 들어간 값을 useState로 변경을 똑같이 해주려고 할 때는 onChange 이벤트를 사용하여 input의 value값을 받아 사용한다. 사용 예시 input에 값을 넣어주면 onChange 함수를 통해 useState의 setter함수에 데이터가 들어간다 import React, { useState } from 'react'; function Input() { const [text, setText] = useState('') const change = (e) => { setText(e.target.value) } const reset = () => { setText('') } return ( 초기화 값:{text} ); }..
2021.11.20