Avoiding style-mismatch
My goal is to position a component randomly inside a grid. But unfortunately I‘m always getting the style-mismatch warning:
I try to achieve my goal with the following code:
I thought that due the style prop is a template literal it would be the easiest to outsource the logic into a computable variable and pass it as a prob. But unfortunately this doesn‘t work..
Hope someone can tell me how to tackle this issue
3 Replies
you have to avoid recalculating the random value on the client and on the server 🙂
you can e.g. use usestate to transfer it over, or use vue-bind-once (or onPreHydrate in Nuxt maybe?) to set the value
GitHub
GitHub - danielroe/vue-bind-once: A tiny, SSR-safe directive for bi...
A tiny, SSR-safe directive for binding random data to an element. - danielroe/vue-bind-once
Looks promising! Definitely taking a look at it ✌🏻