Загрузка видео...

Не удалось загрузить видео

На главную

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

93,875 просмотров • 1 год назад •via X (Twitter)

Комментарии: 10

Фото профиля George Moller
George Moller1 год назад

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 ↓

Фото профиля GreLI
GreLI1 год назад

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.

Фото профиля George Moller
George Moller1 год назад

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

Фото профиля Wouter Raateland
Wouter Raateland1 год назад

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

Фото профиля Basstian
Basstian1 год назад

the DIV as direct child of UL is wrong

Фото профиля micah rich
micah rich1 год назад

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

Фото профиля Maksym_B
Maksym_B1 год назад

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

Фото профиля Filip
Filip1 год назад

So just do the same think as in other frameworks Finally

Фото профиля Pavel Romanov
Pavel Romanov1 год назад

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

Фото профиля Mohammed Arshad Hassan Abdur Rahim Imthiaz
Mohammed Arshad Hassan Abdur Rahim Imthiaz1 год назад

cool

Похожие видео