Lesson 2Trigger side effects with useEffect
useEffect is the most useful hook, but also the one causing the most struggle
among React developers.
You will use it to trigger side effects each time a component’s state or prop is updated. Side effects can be:
- accessing the DOM to get or set an element’s property,
- trigger an asynchronous operation, like a timeout or an HTTP request,
- using some browser API like geolocation, etc.
Basically, any operation that reads a value outside of your component, or writes a value anywhere, can be considered as a side effect. This includes updating a local state.