nuxt-modules / sanity

Sanity integration for Nuxt
https://sanity.nuxtjs.org
MIT License
211 stars 35 forks source link

Is there a method/composable to see if we're in preview mode? #1017

Closed notflip closed 1 day ago

notflip commented 2 weeks ago

I would like to be able to see if we're in preview mode, to conditionally not render things, is this possible? Thanks

rdunk commented 1 week ago

Yes, you should be able to use the useSanityVisualEditingState() composable.

This returns an object with the following signature:

{
  enabled: boolean;
  inFrame: boolean | undefined;
}

inFrame is true if the app is being rendered in a Presentation tool context (i.e. in an iframe). It will always be undefined on the server.

notflip commented 1 day ago

Perfect, Thanks!