Skip to main content

Command Palette

Search for a command to run...

preventDefault() in React

Published
•1 min read•View as Markdown
preventDefault() in React
A

Iam a self learned webdeveloper. Always learning from mistakes.

Hey, so you may have all heard about the preventDefault method if you are a react developer.when i was starting in react i also heard about this method and saw it in so many codes and at that time i didnt know what this is. Then one day i just researched and learned about it. so now i will explain what preventDefault does in react.

So what preventDefault does is that it just stops the default befaviour of an event thats it. Imagine that i have a form in my website and you know how forms works. if we click the submit button it just refresh the page and that is its default behaviour. And if i want to stop refreshing the page after submiting the form which is the default behaviour i will use event.preventDefault() method in onSubmit().

preventDefault is not only applicable to forms it is also applicable in other events like checkbox checking etc..

hope you understood the concept.