react 엔터치면 버튼 눌리기

~_~·2022년 3월 12일
0
import react from "react"

const App = () => {

	const onEnterInput = (e) => {
        if(e.key === 'Enter') {
            handleSubmit();
        }
    }
    
    const handleSubmit = () => {
    	console.log("submit")
    }

	return (
    	<div className="todo_input_wrap">
            <h2>TODO LIST</h2>
            <div className="todo_input">
                <input type="text" onKeyPress={onEnterInput} />
                <button>버튼</button>
            </div>    
        </div>
    )
}

export default App

onKeyPress 를 이용
e.key === 'Enter' 도 이용

0개의 댓글