---
title: "Discussion on \"React hook - useRef - example timer\" | Hashnode"
description: "Discussion on \"React hook - useRef - example timer\". 1. Import các thứ cần thiết\nimport {useState, useEffect, useRef} from 'react'\n2. Tạo ref\nconst interValRef = useRef()\n3. Tạo state timer\nconst [timer, setTimer] = useState(0)\n4. Run timer\nuseEffect(() => {\n  setInterval(() => {\n    setTimer(timer => ..."
url: "https://hashnode.com/posts/react-hook-useref-example-timer/60fa235474648858f4bb6f9a"
---

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

Discussion

# [React hook - useRef - example timer](https://kentrung.hashnode.dev/react-hook-useref-example-timer?utm_source=hashnode&utm_medium=feed)

1\. Import các thứ cần thiết import {useState, useEffect, useRef} from 'react' 2. Tạo ref const interValRef = useRef() 3. Tạo state timer const \[timer, setTimer\] = useState(0) 4. Run timer useEffect(() => { setInterval(() => { setTimer(timer => ...

Jul 23, 2021 · 1 min read · kentrung.hashnode.dev  
Read the article

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

## Written by

[ken trung](https://hashnode.com/@kentrung)

@kentrung · Vietnam

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

developer

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
