You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In some cases, React documentation suggests using a chain of useEffect hooks to manage state updates when synchronizing with network requests. However, it is also possible to handle these scenarios using event handlers effectively.
In the documentation, it states: "In some cases, you can’t calculate the next state directly in the event handler. For example, imagine a form with multiple dropdowns where the options of the next dropdown depend on the selected value of the previous dropdown. Then, a chain of Effects is appropriate because you are synchronizing with network." However, when properly structured, it is also possible to manage these scenarios using event handlers.
For example, in the following setup, we can handle dropdown changes and asynchronous data updates using event handlers:
This approach demonstrates how to manage asynchronous data updates using event handlers, and it may be more suitable in certain situations.
Thanx
Yusuf Kaymaz
The text was updated successfully, but these errors were encountered:
yusufyunuskaymaz
changed the title
[Suggestion]: Usage Of UseEffect
[Suggestion]: Alternative Approach for Managing State with Event Handlers
Jun 14, 2024
Summary
In some cases, React documentation suggests using a chain of useEffect hooks to manage state updates when synchronizing with network requests. However, it is also possible to handle these scenarios using event handlers effectively.
Page
https://react.dev/learn/you-might-not-need-an-effect#sharing-logic-between-event-handlers
Details
Hi,
In the documentation, it states: "In some cases, you can’t calculate the next state directly in the event handler. For example, imagine a form with multiple dropdowns where the options of the next dropdown depend on the selected value of the previous dropdown. Then, a chain of Effects is appropriate because you are synchronizing with network." However, when properly structured, it is also possible to manage these scenarios using event handlers.
For example, in the following setup, we can handle dropdown changes and asynchronous data updates using event handlers:
This approach demonstrates how to manage asynchronous data updates using event handlers, and it may be more suitable in certain situations.
Thanx
Yusuf Kaymaz
The text was updated successfully, but these errors were encountered: