useFormScopeOrContext
Accesses the FormApi
either through explicitly passing a FormScope, or through context.
This is most useful in cases where you have re-usable components and some of your forms use context, while others don't.
This is used internally by hooks like useField
to allow you to pass a field name instead of a scope.
When passing a scope, this behaves exactly like useFormScope
.
When no scope is passed, this behaves exactly like useFormContext
.
If you're using Typescript, you lose a lot of type safety when using the context API
Usage
const MyForm = ({ scope }: { scope?: FormScope<any> }) => {
const form = useFormScopeOrContext(scope);
// ...etc
};