isPreview variable in Gatsby

Off the back of - Github Issue 306

In the new gatsby-plugin-prismic-previews plugin, is there a way I can check if the website is in preview? So that I can show helpers and pointers to content writers?

Hello @thejuniperstudio, Yes, there's an option to check if the preview is on. Angelo, the dev of the plugin, gives us a detailed description of how this works:

If a page is wrapped with one of the plugin's HOCs the page will receive an isPrismicPreview prop. It can be one of three values:

  • true : A preview session is active.
  • false : A preview session is not active.
  • null : Still determining if a preview session is active or not. This may only appear for a split second.

If you need more detailed information, such as which state the preview is in (loading, errored, etc.), the usePrismicPreviewContext() hook can be used. It will return the full state object, including a property called previewState. Here's a full description of the hook’s return value.

1 Like