UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

21 lines (15 loc) 541 B
import {type Serializable} from '@sanity/presentation-comlink' import {useContext, useEffect} from 'react' import {PresentationSharedStateContext} from 'sanity/_singletons' /** @public */ export const useSharedState = (key: string, value: Serializable): undefined => { const context = useContext(PresentationSharedStateContext) if (!context) { throw new Error('Preview Snapshots context is missing') } const {setValue} = context useEffect(() => { setValue(key, value) }, [key, value, setValue]) return undefined }