JSX란? JSX form 종류

Posted by : on

Category : react


state

const [state,setstate] = useState({
   author: "",
   content:"",
   emotion: 1,
 });

  
const handleChangeEvent = (e)=>{
	let name = e.target.name;
	let value = e.target.value;
	setstate({
	  ...state,
	  [name] : value
	})
}

/// state 보내기
const handlesubmmit = ()=>{
	console.log(state)
}

onChange , onClick

input

<input name="author" value={autor} onChange={(e)=>{
     setautor(e.target.value)
}}/>

textarea

<textarea name="content" value={content} onChange={(e)=>{
     setcontent(e.target.value)
}}/>

select

<div>
    <select name="emotion" value={state.emotion} onChange={handleChangeEvent}>
     <option value={1}>1</option>
     <option value={2}>2</option>
     <option value={3}>3</option>
     <option value={4}>4</option>
     <option value={5}>5</option>
    </select>
   </div>

button

<div>
	<button name="save" onClick={handlesubmmit}>일기 저장</button>
</div>

About 유재석
유재석

개발자 유재석 입니다. Web Developer.

Email : jaeseok9405@gmail.com

Website : https://github.com/yoo94