# Providers, hooks, and submit utilities

Canonical page: https://docs.ovok.com/native-sdk/guide/components/questionnaire-response-form/advanced-api

Use the compound [`QuestionnaireForm`](/native-sdk/guide/components/questionnaire-response-form/) for the standard form. The exports on
this page are lower-level building blocks for an app that needs a custom renderer or
navigation UI. They expose implementation state and should be used together with
the documented questionnaire types.

## Providers and hooks [#providers-and-hooks]

| Export | Purpose |
| --- | --- |
| `QuestionnaireFormProvider` | Owns Formik values, validation, and submit behavior for a questionnaire. |
| `QuestionnaireNavigationProvider` | Shares current page/item and navigation actions with navigation children. |
| `useQuestionnaireForm` | Reads form values, errors, submission state, and questionnaire navigation state. |
| `useQuestionnaireNavigation` | Reads the current navigation context. |
| `useQuestionnaireNavigationState` | Derives required, answered, final-item, and progress state from form and navigation inputs. |
| `useNavigationHandlers` | Builds the next/previous handlers used by the standard navigation UI. |
| `useInitialSelectedValues` | Derives initial form values from questionnaire items. |

`useQuestionnaireForm` and `useQuestionnaireNavigation` throw when used outside the
matching provider. `QuestionnaireForm` mounts the form provider for you; the standard
navigation component manages the navigation provider. Prefer those higher-level
components unless you are replacing their rendering behavior.

## Submit utility [#submit-utility]

`QuestionnaireSubmitUtils.createQuestionnaireResponse(responses, pages,
questionnaire)` builds a FHIR `QuestionnaireResponse` with `status: "completed"`, a
reference to the questionnaire, response items, and an authored timestamp. It does
not add subject, encounter, author, or provenance details. Add the context required
by your workflow before persisting the resource.

The standard form can either call your `onSubmit(values)` handler or, when that
handler is omitted, produce the FHIR response and report it through `onSuccess`.
Choose one path deliberately and handle failures at the screen boundary.

## Contexts and types [#contexts-and-types]

The subpath also exports `QuestionnaireFormContext`,
`QuestionnaireNavigationContext`, their context/provider types, `QuestionnaireFormProps`,
`QuestionnaireFormValues`, `ResponseValues`, `ExtendedQuestionnaireItem`, and the FHIR
`QuestionnaireResponse` type. Use the hooks in component code instead of reading
contexts directly.
