3 ms·
> const inc = useCallback(() => setI(currentI => currentI + 1)); This might actually even have a bug and would need to be even longer to properly function :-D
by axiosgunnar 5y ago
> const inc = useCallback(() => setI(currentI => currentI + 1));
This might actually even have a bug and would need to be even longer to properly function :-D
I think you need to add [i] as a dependency, no?
- kabes 5y agoNo. I'm using a callback in the setter which gives me the latest i and the setter never changes. If instead I would use setI(i+1) I'd have to add i as a dependency, but since state updates happen asynchronous, this would have a bug when calling it multiple times before the state is flushed.