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)
a bit late to the party but...
someTokenizeFunction
returns null instead of new stateCorrect! In that case it treats
someTokenizeFunction
as a state setter and not as a state in itself.