Sanity Library Reference Docs
    Preparing search index...

    Function useFormValue

    • React hook that returns the value of the field specified by a path, or the whole document when called without one.

      Parameters

      • path: Path = ROOT_PATH

        An array notation with segments that are either strings representing field names, index integers for arrays with simple values, or objects with a _key for arrays containing objects. Defaults to the document root.

      Returns unknown

      The value of the field specified by the path, or the whole document if no path is given

      function MyComponent() {
      // get the whole document
      const document = useFormValue()
      // get value of field 'name' in object 'author'
      const authorName = useFormValue(['author', 'name'])
      // get value of the second item in array 'tags' of type 'string'
      const secondTag = useFormValue(['tags', 1])
      // get value of the reference with the matching key in an array of references
      const specificBook = useFormValue([ 'bibliography', {_key: '<key>'} ])
      // ... do something with the form values ...
      }