DEV Community

Dmitri Pisarev 🇷🇺
Dmitri Pisarev 🇷🇺

Posted on

1

React quiz: spot a bug

A few month ago I've posted this trick snippet on Twitter... And then I even forgot what the problem was myself!

const [tokenize, setTokenize] = useState(null)
const someTokenizeFunction = () => null
useEffect(() => {
  setTokenize(someTokenizeFunction)
}, [])

Can you spot a bug? Write in the comments!

Could make a nice interview question, huh?

Top comments (2)

Collapse
 
alekslario profile image
Aleksandrs Larionovs • Edited

a bit late to the party but...someTokenizeFunction returns null instead of new state

Collapse
 
dimaip profile image
Dmitri Pisarev 🇷🇺

Correct! In that case it treats someTokenizeFunction as a state setter and not as a state in itself.

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay