Skip navigation
⚛️ Use callback ref functions instead of useEffect (when possible) ↓
0:00 / 0:34

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

George Moller

@_georgemoller117K followers

Visit on X
1,449 likesDownloadOriginal post

94,184 views

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

10 Comments

Comments from the original post on X (Twitter)

  • George Moller's profile picture

    @_georgemoller

    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 ↓

    9 likes

  • GreLI's profile picture

    @ruGreLI

    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.

    14 likes

  • George Moller's profile picture

    @_georgemoller

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

    4 likes

  • Wouter Raateland's profile picture

    @wouterraateland

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

    3 likes

  • Basstian's profile picture

    @_basstian_

    the DIV as direct child of UL is wrong

    2 likes

  • micah rich's profile picture

    @micahbrich

    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

    2 likes

  • Maksym_B's profile picture

    @MaksymB6

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

    2 likes

  • Filip's profile picture

    @FSkoczen6312

    So just do the same think as in other frameworks Finally

    1 like

  • Pavel Romanov's profile picture

    @pavl_ro

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

    1 like

  • Mohammed Arshad Hassan Abdur Rahim Imthiaz's profile picture

    @ft_arshad

    cool

    1 like