---
title: "Discussion on \"The basics of React useRef Hook with Examples\" | Hashnode"
description: "Discussion on \"The basics of React useRef Hook with Examples\". Introduction\nHey there 👋, my name is Olix, and this is my first blog entry. Recently, useRef got introduced to us in AltSchool, and the explanation was so concise that I decided to share my thoughts.\nWhat is useRef, first, before we continue?\nIn ver..."
url: "https://hashnode.com/posts/the-basics-of-react-useref-hook-with-examples/63430ee129558655566c6aff"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [The basics of React useRef Hook with Examples](https://olix.com/the-basics-of-react-useref-hook-with-examples?utm_source=hashnode&utm_medium=feed)

Introduction Hey there 👋, my name is Olix, and this is my first blog entry. Recently, useRef got introduced to us in AltSchool, and the explanation was so concise that I decided to share my thoughts. What is useRef, first, before we continue? In ver...

Oct 9, 2022 · 3 min read · olix.com  
Read the article

-   [#useref](https://hashnode.com/tag/useref)
-   [#reactjs](https://hashnode.com/tag/reactjs)

## Written by

[Noibi Abdulrasaq](https://hashnode.com/@Olix)

@Olix

  
[View profile](https://hashnode.com/@Olix)

Software Engineer

## Responses 1

Markdown supported · ⌘↵ to post

[Said Mounaim](https://hashnode.com/@smounaim)

[Oct 9, 2022](https://hashnode.com/posts/the-basics-of-react-useref-hook-with-examples/63430ee129558655566c6aff/comment/6343223d0961ceed80d09ceb)

Thanks ! and another example if we want to know how many times our Application renders with useState, we can't we get infinite loop cuz useState itself causes a re rendring, for that we can use useRef Hook

```
import { useState, useEffect, useRef } from "react";

function App() {
  const [inputValue, setInputValue] = useState("");
  const count = useRef(0);

  useEffect(() => {
    count.current = count.current + 1;
  });

  return (
    <>
      <input
        type="text"
        value={inputValue}
        onChange={(e) => setInputValue(e.target.value)}
      />
      <h1>Render Count: {count.current}</h1>
    </>
  );
}
```

[Noibi Abdulrasaq](https://hashnode.com/@Olix)

[Oct 10, 2022](https://hashnode.com/posts/the-basics-of-react-useref-hook-with-examples/63430ee129558655566c6aff/comment/6343223d0961ceed80d09ceb#reply-634388ba250857e669efedd2)

Thank you for the feedback! Great example [Said Mounaim](https://hashnode.com/@smounaim) Just to add; we can say; the state hook should be used for component re-rendering and the ref hook for information needed by event listeners and thus does not require component re-rendering.
