Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

⚛️ Use callback ref functions instead of useEffect (when possible) ↓

93,875 Aufrufe • vor 1 Jahr •via X (Twitter)

10 Kommentare

Profilbild von George Moller
George Mollervor 1 Jahr

I've been working professionally with React for more than 8 years and I compiled all my knowledge into 100+ infographics and 70+ video tutorials just like this one. Check them out ↓

Profilbild von GreLI
GreLIvor 1 Jahr

There is a caveat: callback refs are re-evaluated every time they changed. So if the component rerenders (often because parent does), it's better to memoize them, until you're using React Compiler. Otherwise you can get an extra action when you're not expecting it.

Profilbild von George Moller
George Mollervor 1 Jahr

yup, or you can move the callback function outside the components scope, that works too.

Profilbild von Wouter Raateland
Wouter Raatelandvor 1 Jahr

Be aware that `scrollIntoView` gets called with `null` when the component unmounts. This version will error. Rather use `(node: HTMLDivElement | null)` and `node?.scrollIntoView(...)`.

Profilbild von Basstian
Basstianvor 1 Jahr

the DIV as direct child of UL is wrong

Profilbild von micah rich
micah richvor 1 Jahr

Oh dang this is interesting. Does this mean this can go from a client component to a server component? Also - any other examples you see often? This makes me so curious

Profilbild von Maksym_B
Maksym_Bvor 1 Jahr

@onix_react тут є гарні поради

Profilbild von Filip
Filipvor 1 Jahr

So just do the same think as in other frameworks Finally

Profilbild von Pavel Romanov
Pavel Romanovvor 1 Jahr

This one was catchy at first, but when you get it right things work like magic

Profilbild von Mohammed Arshad Hassan Abdur Rahim Imthiaz
Mohammed Arshad Hassan Abdur Rahim Imthiazvor 1 Jahr

cool

Ähnliche Videos