News for hackers. Stuff that matters.
Re:Not using useCallback is premature optimization by zastrowm on Wednesday August 17, 2022 @09:01PM (#32503904)
For this specific example the problem is that the handleClick callback is using a stale/cached onImageDeleted callback (which indirectly has old state). If you add onImageDeleted to the handleClick dependency array, it beings to work as you expect.
Re:Not using useCallback is premature optimization by tylerhou on Wednesday August 17, 2022 @10:05PM (#32504346)
Would the dependency linter catch this? I assume yes?
Re:Not using useCallback is premature optimization by tpict on Wednesday August 17, 2022 @11:33PM (#32504959)
Yep, it will flag any references to variables in the outer scope that it doesn’t know for certain are stable.
Re:Not using useCallback is premature optimization by Rodeoclash on Wednesday August 17, 2022 @11:05PM (#32504771)
Ahh, that's interesting.