Sanity Library Reference Docs
    Preparing search index...

    Function useGetFormValue

    • React hook that returns a function that can be called to look up the value from the current document at the given path. The returned function is stable and never changes identity. NOTE: This hook will not trigger a re-render when the value of the document changes, which makes it less suitable for use in render functions. The main use case for using this is to look up values at the current document during an event handler

      Returns GetFormValueContextValue

      A function that can be called to look up the value from the current document at the given path.

      function MyComponent() {
      // get value of field 'name' in object 'author'
      const getFormValue = useGetFormValue()

      const handleClick = useCallback(() => {
      console.log(getFormValue(['author', 'name']))
      }, [getFormValue])
      }