Reading-Notes

Reading

useEffect hook

What is the main intended use case for the useEffect hook?

To declare an effect. It allows you to perform certain actions in response to component updates, such as fetching data, subscribing to events, or manually manipulating the DOM.

How does the effect’s logic interact with the component?

  1. When the component is first shown on the screen:
    • The effect’s code runs after the component is displayed.
    • You can use this to set things up, like initializing variables or fetching data.
  2. Whenever the component’s data or appearance changes:
    • The effect’s code runs again.
    • You can respond to these changes by performing additional actions or updating the component’s state.
  3. Before the component is removed from the screen:
    • The effect’s cleanup code (if provided) runs.
    • You can use this to clean up any resources or subscriptions created by the effect.

What is the importance of the return value from the effect’s logic function?

The main reason to use the return value from the effect’s logic funtion is to ensure that any side effects initiated by the ‘effect’ are properly disposed of. It’s important for maintaining an efficient app and preventing memory leaks especially when used with long-lived components or components the mount and unmount frequently.

Bookmark and Review Keep these pages handy - they answer questions that show up regularly for this lab.

Responding to Events Conditional Rendering Updating Arrays in State Updating Objects in State

Reflection

What are your learning goals after reading and reviewing the class README?

Being able to use the ‘useEffect’ appropriately, it has a lot of aspects too it, all of which seem helpful, as long as it’s used properly.