Hydration mismatch for breakpoints

i have an isMobile ref that always throws a hydration mismatch. Its a composable that is a resize listener so it always knows if the viewport isMobile or not. On the server its false, on the client its true. This didn't happen with nuxt2. Right now as a workaround, i have to use an isMounted composable:
const isMounted = useMounted();
const isMounted = useMounted();
variable on my component like v-if=isMounted to not get that error. is there a better way?
5 Replies
pyplacca
pyplacca5mo ago
If the component isn’t needed to be rendered on the server side, you could wrap it in the client-only component
localhostess
localhostess5mo ago
Thanks for the response! That would work in an individual component. Lets say in my nuxt layout.vue, i wanted to load various components for a mobile experience, or other ones for desktop. Before, in nuxt2 i would just setup the isMobile ref that gets the viewport width, and a resize listener to listen for viewport size to render one experience or the other. What would be the preferred way to handle this ya think?
Bibliophage
Bibliophage5mo ago
GitHub
GitHub - mvrlin/nuxt-viewport: 🌈 Define custom viewports for your ...
🌈 Define custom viewports for your Nuxt project. Contribute to mvrlin/nuxt-viewport development by creating an account on GitHub.
localhostess
localhostess5mo ago
oooo ty.. will check this out!! 🙏
Cake
Cake5mo ago
u might need to just switch to useState instead of a ref
Want results from more Discord servers?
Add your server