3 ms·
Yeah, and sometimes it feels like I'm writing a really cumbersome dialect of javascript. I mean, something simple like: let i = 0; const inc = () => i+=1;
by kabes 5y ago
Yeah, and sometimes it feels like I'm writing a really cumbersome dialect of javascript.
I mean, something simple like:
let i = 0;
const inc = () => i+=1;
becomes:
const [i, setI] = useState(0);
const inc = useCallback(() => setI(currentI => currentI + 1));
Every single thing needs layers of abstractions upon layers of abstractions.
For all the hate angularJS got, at least with dirty checking your javascript was just plain javascript. I'm leaning more and more towards svelte, which offers this, but more performant than with dirty checking.
- 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.
- 5Qn8mNbc2FNCiVV 5y agoThe useCallback is redundant, the rest is still valid but I'd rather have it this way than magical variables where a reassignment makes the framework do work. This way I can just find all references of "setI"