How to use the @sanity/react-hooks.useEditState function in @sanity/react-hooks

To help you get started, we’ve selected a few @sanity/react-hooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sanity-io / sanity / packages / @sanity / desk-tool / src / pane / DocumentPaneProvider.tsx View on Github external
export const DocumentPaneProvider = withInitialValue((props: Props) => {
  const {patch, commit}: any = useDocumentOperation(props.options.id, props.options.type)
  const editState: any = useEditState(props.options.id, props.options.type)

  const runThrottled = useThrottled(run => run(), 1000, {leading: true, trailing: true}, [])

  const value = (editState && (editState.draft || editState.published)) || props.initialValue
  return (
     {
        patch.execute(patches)
        runThrottled(commit.execute)
      }}
      value={value}
      draft={editState && editState.draft}
      published={editState && editState.published}
      markers={editState ? editState.validation : []}
      isLoading={!editState}
github sanity-io / sanity / packages / @sanity / desk-tool / src / components / DocumentStatusBar / DocumentStatusBarActions.tsx View on Github external
export function HistoryStatusBarActions(props: HistoryStatusBarActionsProps) {
  const editState: any = useEditState(props.id, props.type)

  if (!editState) {
    return null
  }
  const actionProps = {...editState, historyId: props.historyId, revision: props.revision}
  return (
     {
        /*todo: make optional*/
      }}
    />
  )
}
github sanity-io / sanity / packages / @sanity / desk-tool / src / components / DocumentStatusBar / DocumentStatusBarActions.tsx View on Github external
export function DocumentStatusBarActions(props: Props) {
  const editState = useEditState(props.id, props.type)
  const [isMenuOpen, setMenuOpen] = React.useState(false)

  const actions = editState ? resolveDocumentActions(editState) : null

  return actions ? (
     setMenuOpen(true)}
      onMenuClose={() => setMenuOpen(false)}
      onActionComplete={() => setMenuOpen(false)}
      actions={actions}
      actionProps={editState}
    />
  ) : null
}

@sanity/react-hooks

Officially supported Sanity Studio API building blocks

MIT
Latest version published 1 year ago

Package Health Score

79 / 100
Full package analysis