Skip to content

Commit 89cd5ee

Browse files
committed
small edits in preventDefault
1 parent d9fb5d1 commit 89cd5ee

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

React/preventDefault-in-React.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@ const ListWithAddItem = () => {
5151
export default ListWithAddItem;
5252
```
5353

54-
Why is a form submit reloading the browser? All native HTML elements come with their internal native behavior. For instance, input elements store their internal state. That’s why often React is used to take over for having controlled components by managing the state via React. The same applies for a form element which has a submit event that is invoked via a submit button element. In the past, it was desired to refresh the browser to flush all state and to submit the data to a backend. Nowadays, a library such as React, gives us more flexibility to deal with the submit event ourselves. In this case, we deal with it by updating the list in our component’s state.
54+
Without a preventDefault() a form submission will reload the browser.
5555

56-
In another scenario, you may fetch data from a backend and store it in your component’s state. There is no native submission from the form expected anymore, that’s why the developer is able to take over. The developer shouldn’t need to worry about any undesired behavior of the browser.
56+
Because, all native HTML elements come with their internal native behavior. For instance, input elements store their internal state. That’s why often React is used to take over for having controlled components by managing the state via React.
57+
58+
Similarly a Form element which has a submit event that is invoked via a submit button element, in the past, was desired to refresh the browser to flush all state and to submit the data to a backend. But with React, it gives us more flexibility to deal with the submit event ourselves by invoking the preventDefault()
59+
60+
In another scenario, you may fetch data from a backend and store it in your component’s state. There is no native submission from the form expected anymore, that’s why the developer is able to take over.
61+
62+
In another scenario, you may fetch data from a backend and store it in your component’s state. There is no native submission from the form expected anymore, and the developer should be able to take over in this situation, so he shouldn’t need to worry about any undesired behavior of the browser.
5763

5864
#### Reading
5965

0 commit comments

Comments
 (0)