DEV Community

Dmitri Pisarev πŸ‡·πŸ‡Ί
Dmitri Pisarev πŸ‡·πŸ‡Ί

Posted on

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.