feat: attempt to fix the crud with auth
This commit is contained in:
13
contexts/FormField/FormFieldContext.ts
Normal file
13
contexts/FormField/FormFieldContext.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import React from 'react';
|
||||
import { FieldPath, FieldValues } from 'react-hook-form';
|
||||
|
||||
interface FormFieldContextValue<
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
|
||||
> {
|
||||
name: TName;
|
||||
}
|
||||
|
||||
export const FormFieldContext = React.createContext<FormFieldContextValue>(
|
||||
{} as FormFieldContextValue
|
||||
);
|
||||
20
contexts/FormField/FormFieldProvider.tsx
Normal file
20
contexts/FormField/FormFieldProvider.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import {
|
||||
Controller,
|
||||
ControllerProps,
|
||||
FieldPath,
|
||||
FieldValues
|
||||
} from 'react-hook-form';
|
||||
import { FormFieldContext } from './FormFieldContext';
|
||||
|
||||
export const FormField = <
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
|
||||
>({
|
||||
...props
|
||||
}: ControllerProps<TFieldValues, TName>) => {
|
||||
return (
|
||||
<FormFieldContext.Provider value={{ name: props.name }}>
|
||||
<Controller {...props} />
|
||||
</FormFieldContext.Provider>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user