---
title: "ken trung (@kentrung) | Hashnode"
description: "developer. Read the latest articles by ken trung on Hashnode."
url: "https://hashnode.com/@kentrung"
---

@kentrung

# ken trung

@kentrung · Vietnam · Joined June 2021

developer

### [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 => ...

1 min read · [kentrung.hashnode.dev](https://kentrung.hashnode.dev/react-hook-useref-example-timer?utm_source=hashnode&utm_medium=feed)

[Jul 23, 2021](https://hashnode.com/posts/react-hook-useref-example-timer/60fa235474648858f4bb6f9a)

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

useRef giúp chúng ta thao tác và xử lý DOM 1. Import các thứ cần thiết import { useEffect, useRef } from 'react' 2. Tạo ref const inputRef = useRef() 3. Gắn ref vào input <input type="text" ref={inputRef} /> 4. Tự động focus khi page loaded useEffect...

1 min read · [kentrung.hashnode.dev](https://kentrung.hashnode.dev/react-hook-useref-auto-focus-input?utm_source=hashnode&utm_medium=feed)

[Jul 22, 2021](https://hashnode.com/posts/react-hook-useref-auto-focus-input/60f8f67f3e181324dac7428d)

### [React hook - useReducer vs useState](https://kentrung.hashnode.dev/react-hook-usereducer-vs-usestate?utm_source=hashnode&utm_medium=feed)

Cả hai hook này đều làm nhiệm vụ quản lí state, cùng tìm hiểu khi nào thì nên dùng hook tương ứng để đạt hiệu quả cao.

1 min read · [kentrung.hashnode.dev](https://kentrung.hashnode.dev/react-hook-usereducer-vs-usestate?utm_source=hashnode&utm_medium=feed)

[Jul 20, 2021](https://hashnode.com/posts/react-hook-usereducer-vs-usestate/60f6974f08a35e79f1fd1d73)

### [React hook - useReducer - complex State & Action](https://kentrung.hashnode.dev/react-hook-usereducer-complex-state-and-action?utm_source=hashnode&utm_medium=feed)

1\. Các bước làm 1-1. Import useReducer import { useReducer } from 'react' 1-2. Khởi tạo giá trị ban đầu const initialState = { firstName: 'Ken', lastName: 'Trung' } 1-3. Tạo hàm reducer Hàm này nhận 2 tham số Tham số 1 là state muốn thay đổi giá trị...

2 min read · [kentrung.hashnode.dev](https://kentrung.hashnode.dev/react-hook-usereducer-complex-state-and-action?utm_source=hashnode&utm_medium=feed)

[Jul 18, 2021](https://hashnode.com/posts/react-hook-usereducer-complex-state-and-action/60f4530bbb67011cb836c651)

### [React hook - useReducer - simple State & Action](https://kentrung.hashnode.dev/react-hook-usereducer-simple-state-and-action?utm_source=hashnode&utm_medium=feed)

1\. Các bước làm 1-1. Import useReducer import { useReducer } from 'react' 1-2. Khởi tạo giá trị ban đầu const initialState = 0 1-3. Tạo hàm reducer Hàm này nhận 2 tham số Tham số 1 là state muốn thay đổi giá trị Tham số 2 là action Tùy vào loại acti...

2 min read · [kentrung.hashnode.dev](https://kentrung.hashnode.dev/react-hook-usereducer-simple-state-and-action?utm_source=hashnode&utm_medium=feed)

[Jul 18, 2021](https://hashnode.com/posts/react-hook-usereducer-simple-state-and-action/60f3f00d66fcdb0a02743916)
