setUserInput((prevState) => {
return { ...prevState, enteredTitle : event.target.value };
});
callback function 으로 순서를 보장 후 보내준다.
오늘의 연습 React
import React, { useState } from 'react';
import './styles.css';
// don't change the Component name "App"
export default function App() {
const [inputLengthCheck, setInputLengthCheck] = useState("Invalid message");
const isPasswordValidHandle = (event) => {
if (event.target.value.trim().length < 3) {
setInputLengthCheck('Invalid message');
}else {
setInputLengthCheck('Valid message');
}
};
return (
<form>
<label>Your message</label>
<input type="text" onChange={isPasswordValidHandle}/>
<p>{inputLengthCheck}</p>
</form>
);
}