#author("2023-01-23T03:35:47+09:00","default:ryuichi","ryuichi")
#author("2023-02-02T18:28:52+09:00;2023-01-23T03:35:47+09:00","default:ryuichi","ryuichi")
* いつなぜuseEffectを使うべきか? [#dbb2ea76]



> This example highlights the importance of understanding when useEffect should be used. useEffect is for triggering code in response to the screen updating, not for triggering code in response to an event, such as a user interaction.
>
> この例は、useEffect をいつ使用する必要があるかを理解することの重要性を強調しています。 useEffect は、画面の更新に応答してコードをトリガーするためのものであり、ユーザーの操作などのイベントに応答してコードをトリガーするためのものではありません。

*** つまり、 [#fc003d9c]
ユーザーがボタン押下するとAPIリクエストするような処理があるとして、useEffectの中でAPIリクエストするのではなく、ボタン押下イベントのハンドラーですべき

** 参考 [#ze02d1ce]

https://medium.com/redsquirrel-tech/improve-your-knowledge-of-reacts-useeffect-with-5-exercises-361c2c2fcf4e

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS