@TommyD For working code consider
codereview.stackexchange.com instead, as this is beyond the scope of SO. useEffect with [] means that code is executed only on client side, it goes to mounted hook, and a cleanup goes to unmounted hook. Which seems to be the thing that you did already. "performant way" isn't very relevant, as you don't do anything performance critical here. You can use shallowRef or useTemplateRef for a ref to avoid unnecessary deep reactivity, but it's insignificant —
Estus Flask 52 secs ago