Skip to content

Commit

Permalink
Provide way to cast useFormContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Stramel committed Aug 15, 2019
1 parent f67837f commit a8847d8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/useFormContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ const FormGlobalContext = React.createContext<FormContextValues<
DataType
> | null>(null);

export function useFormContext() {
return React.useContext(FormGlobalContext)!;
export function useFormContext<T extends DataType>(): FormContextValues<T> {
// @ts-ignore
return React.useContext(FormGlobalContext);
}

export function FormContext<T extends DataType>(props: FormProps<T>) {
export function FormContext(props: FormProps<DataType>) {
const { children, ...rest } = props;
return (
<FormGlobalContext.Provider value={rest as FormContextValues}>
<FormGlobalContext.Provider value={rest}>
{children}
</FormGlobalContext.Provider>
);
Expand Down

0 comments on commit a8847d8

Please sign in to comment.