Sanity Library Reference Docs
    Preparing search index...

    Function useFormValue

    • React hook that returns the value of the field specified by a path.

      Parameters

      • path: 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

      Returns unknown

      The value of the field specified by the path

      function MyComponent() {
      // 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 ...
      }