sarahdellysse
Joined 15 years ago
Karma
513
Submissions
86
Member since
Oct 14
Joined 15 years ago
const foo = `aaaaaaaaaaaaaaa${bbbbbbbbbbbbb}ccccccccccccccc${ddddddddddd}`;
prettier would fix it to const foo =
`aaaaaaaaaaaaaaa${
bbbbbbbbbbbbb
}ccccccccccccccc${
ddddddddddd
}`;
(or something similar) and it would be fully equivalent.I don't like it doing that either tbh but hey prettier is good enough in most cases its worth putting up with it
for now
const useCallback = (fn, deps) => useMemo(() => fn, deps);
That's it. That's all it is. `useCallback` is a shorthand for `useMemo`, when you want to memo a function definition.Example:
const handleButtonClick = useCallback((event) => {
event.preventDefault();
window.alert(`Hello, ${name}!`)
}, [name])
is just shorthand for const handleButtonClick = useMemo(() => (event) => {
event.preventDefault();
window.alert(`Hello, ${name}!`)
}, [name])