using ref alongside conditional rendering (useTemplateRef + v-if)
I fixed it. It was because the useTemplateRef is initialized before the component actually gets rendered so it is undefined at first. I used a watcher on the useTemplateRef and the interesting part is that it is reactive.