React is Simple!

Think React state is easy? One wrong move and your counter breaks.

Why It Happens

React batches state updates.
Using setState(state + 1) can overwrite updates with stale values.
The functional form setState(prev => prev + 1) ensures correctness.

Don't

const [count, setCount] = useState(0);

setCount(count + 1);
setCount(count + 1); 
// ❌ Result: count = 1

Do

const [count, setCount] = useState(0);

setCount(prev => prev + 1);
setCount(prev => prev + 1);
// ✅ Result: count = 2

Explanation

  • setCount(count + 1) → uses an old snapshot of state.
  • setCount(prev => prev + 1) → React passes the freshest value.

Updating state without prev is like asking for “one more slice” 🍕…
but the box already got emptied. Always ask from the current box.

3

A software engineer in Seoul, and a father of a kid.

Neovim Super villain. 풀스택 엔지니어 내지는 프로덕트 엔지니어라고 스스로를 소개하지만 사실상 잡부를 담당하는 사람. CLI 도구를 만드는 것에 관심이 많습니다.

Hackers' Pub에서는 자발적으로 바이럴을 담당하고 있는 사람. Hackers' Pub의 무궁무진한 발전 가능성을 믿습니다.

그 외에도 개발자 커뮤니티 생태계에 다양한 시도들을 합니다. 지금은 https://vim.kr / https://fedidev.kr 디스코드 운영 중

게임 디자이너에서 웹으로 넘어가려고 하고 있어요~

よく使う:Java

深掘りしたい:Go

勉強中:React、TypeScript,, Python

Hi, I'm who's behind Fedify, Hollo, BotKit, and this website, Hackers' Pub! My main account is at @hongminhee洪 民憙 (Hong Minhee).

Fedify, Hollo, BotKit, 그리고 보고 계신 이 사이트 Hackers' Pub을 만들고 있습니다. 제 메인 계정은: @hongminhee洪 民憙 (Hong Minhee).

FedifyHolloBotKit、そしてこのサイト、Hackers' Pubを作っています。私のメインアカウントは「@hongminhee洪 民憙 (Hong Minhee)」に。