Languages

React - how to stop page reloading onSubmit?

3 points
Asked by:
Zayyan-Todd
860

I'm trying to add some items to the list but when onSubmit event occurs my App is re-rendering without new item. Do you know how to fix this?

My code:

1 answer
4 points
Answered by:
maxsior322
347

I found the solution:

The problem was I forgot to pass event as props to the handleSubmit method like I did with handleChange. Then I used event.preventDefault(); which prevented App re-rendering.

Runnable example:

0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join