The useEffect Hook Examples

Learn about two practical examples of using the useEffect hook in React: finding the window size dynamically and fetching an API resource.

The useEffect hook is normally used for any side effect—whether that is to read from an external object or write to an external object. In this lesson, we'll see two more examples: finding the window size and fetching an API resource.

Finding the window size

Let's say that we want to know the current browser window size at runtime so that a greeting title can fit perfectly onto the screen (see the image below):

Get hands-on with 1400+ tech skills courses.