'Page reload onChange on type
Im trying to console.log the input value inside Input but every time i type something the page reloads. Console show no errors.
const [enteredText, setEnteredText] = useState("");
const textHandler = (event) => {
setEnteredText(event.target.value);
};
const submitHandler = (event) => {
event.preventDefault();
const textData = {
text: enteredText,
};
console.log(textData);
};
return (
<Post onSubmit={submitHandler}>
<TopPost>
<ProfilePicture></ProfilePicture>
<Input
placeholder="What's happening?"
required
onChange={textHandler}
/>
</TopPost>
<BottomPost>
<Button type="submit">Post</Button>
</BottomPost>
</Post>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
