UNPKG

@sanity/scheduled-publishing

Version:

> [!IMPORTANT] > As of [v3.39.0](https://www.sanity.io/changelog/e6013ee5-8214-4e03-9593-f7b19124b8a3) of Sanity Studio, this plugin has been deprecated and the Scheduled Publishing functionality has been moved into the core studio package. > Read more an

32 lines (27 loc) 853 B
import {SchemaType, useDocumentPreviewStore} from 'sanity' import {useEffect, useState} from 'react' import {getPreviewStateObservable, PaneItemPreviewState} from '../utils/paneItemHelpers' export default function usePreviewState( documentId: string, schemaType?: SchemaType ): PaneItemPreviewState { const documentPreviewStore = useDocumentPreviewStore() const [paneItemPreview, setPaneItemPreview] = useState<PaneItemPreviewState>({}) useEffect(() => { if (!schemaType) { return undefined } const subscription = getPreviewStateObservable( documentPreviewStore, schemaType, documentId, '' ).subscribe((state) => { setPaneItemPreview(state) }) return () => { subscription?.unsubscribe() } }, [documentPreviewStore, schemaType, documentId]) return paneItemPreview }