<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/react-s-useeffect-and-useref-explained-for-mortals-sqvdoiuba" -->

---
title: React&#x27;s useEffect and useRef Explained for Mortals
description: This post explains the purpose of useEffect in React, how side effects are handled in class-based components, and how to fix the stale closure problem with...
canonical: https://daily.dev/posts/react-s-useeffect-and-useref-explained-for-mortals-sqvdoiuba
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: React&#x27;s useEffect and useRef Explained for Mortals | daily.dev
og:description: This post explains the purpose of useEffect in React, how side effects are handled in class-based components, and how to fix the stale closure problem with...
og:url: https://daily.dev/posts/react-s-useeffect-and-useref-explained-for-mortals-sqvdoiuba
og:image: https://api.daily.dev/og/posts/sQvdoiuba.png
og:image:alt: React&#x27;s useEffect and useRef Explained for Mortals
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# React's useEffect and useRef Explained for Mortals

**[Community Picks](https://daily.dev/sources/community)** · 13 min read · 31 upvotes · 2 comments

## Summary

This post explains the purpose of useEffect in React, how side effects are handled in class-based components, and how to fix the stale closure problem with useEffect.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://leewarrick.com/blog/react-use-effect-explained/>

## Community discussion

Top comments from developers on daily.dev.

**@friedrich** · 1 upvotes

> Very clear and extremely well detailled article on React hooks. I always get confused by useEffect and useRef, when do we have re-render, when we don't...
>
> That shows that React is pretty simple at surface but is, in fact, a complex library that makes easy to shoot yourself in the foot if you don't really understand what is going on.

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#react](https://daily.dev/tags/react), [#react-hooks](https://daily.dev/tags/react-hooks)

[View this post on daily.dev](https://daily.dev/posts/react-s-useeffect-and-useref-explained-for-mortals-sqvdoiuba)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"React's useEffect and useRef Explained for Mortals","url":"https://daily.dev/posts/react-s-useeffect-and-useref-explained-for-mortals-sqvdoiuba","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/react-s-useeffect-and-useref-explained-for-mortals-sqvdoiuba"},"datePublished":"2024-05-03T05:33:45.947Z","dateModified":"2024-05-09T08:22:04.995Z","description":"This post explains the purpose of useEffect in React, how side effects are handled in class-based components, and how to fix the stale closure problem with...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/078a8181afc9ae4877b67dcbb38b8f33?_a=AQAEuiZ","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/078a8181afc9ae4877b67dcbb38b8f33?_a=AQAEuiZ","isAccessibleForFree":true,"articleSection":"Community Picks","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Community Picks","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1655817725/logos/community","url":"https://daily.dev/sources/community"},"commentCount":2,"discussionUrl":"https://daily.dev/posts/react-s-useeffect-and-useref-explained-for-mortals-sqvdoiuba","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":31},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":2}],"keywords":"javascript,react,react-hooks","timeRequired":"PT13M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Community Picks","item":"https://daily.dev/sources/community"},{"@type":"ListItem","position":3,"name":"React's useEffect and useRef Explained for Mortals"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/react-s-useeffect-and-useref-explained-for-mortals-sqvdoiuba","comment":[{"@type":"Comment","text":"Very clear and extremely well detailled article on React hooks. I always get confused by useEffect and useRef, when do we have re-render, when we don’t…\nThat shows that React is pretty simple at surface but is, in fact, a complex library that makes easy to shoot yourself in the foot if you don’t really understand what is going on.","datePublished":"2024-05-04T07:53:08.269Z","url":"https://daily.dev/posts/sQvdoiuba#c-g7pQvhips","author":{"@type":"Person","name":"Friedrich WT","url":"https://daily.dev/friedrich","image":"https://avatars.githubusercontent.com/u/136119888?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}}]}
```

