const Id = (handleIdChange) => {
return (
<label>ID: </label>
<input onChange={handleIdChange} />
)
}
const Passsword = (handlePasswordChange) => {
return (
<label>ID: </label>
<input onChange={handlePasswordChange} />
)
}
const App = () => {
const [id, setId] = React.useState("")
const [password, setPassword] = React.useState("")
const handleLoginClick = (event) => {
event.preventDefault()
alert(`id: ${id.length}, password: ${password.length}`)
}
const handleIdChange = (event) => {
setId(event.target.value.length)
}
const handlePasswordChage = (event) => {
setPassword(event.target.value.length)
}
return (
<>
<Id handleIdChange={handleIdChange} />
<Password handlePasswordChange={handlePasswordChange} />
<button onClick={handleLoginClick} disabled={ id === 0 || password === 0}>Login</button>
</>
)
}
ReactDOM.reander(<App />, rootElement)