I made a simple react controlled input that store the value in a state and i dont understand why when i press a key for the first time the console log shows "".
Here is my code
class Form extends React.Component {
constructor(props) {
super(props);
this.state = {
value: "",
};
}
handleForm = (e) => {
console.log("test");
e.preventDefault();
};
handleUsername = (e) => {
this.setState({ value: e.target.value });
console.log(this.state);
};
render() {
return (
<>
<div>
<form onSubmit={this.handleForm}>
<input
onChange={this.handleUsername}
type="text"
placeholder="username"
value={this.state.value}
/>
<input type="submit" />
</form>
</div>
</>
);
}
}
export default Form;