Skip to content

Commit

Permalink
Merge pull request #158 from binary-butterfly/improve-context-type
Browse files Browse the repository at this point in the history
Improve withFormifly type
  • Loading branch information
DysphoricUnicorn committed Mar 11, 2024
2 parents 318d40a + b5e875c commit 1b1c4d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "formifly",
"version": "2.8.5",
"version": "2.8.6",
"description": "React form handling as light as a butterfly",
"main": "dist/formifly.umd.js",
"module": "dist/formifly.js",
Expand Down
13 changes: 8 additions & 5 deletions src/js/components/meta/withFormifly.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import React from 'react';
import {FormiflyContextType, useFormiflyContext} from './FormiflyContext';
import ObjectValidator from '../../classes/ObjectValidator';

const withFormifly = <T extends ObjectValidator<any>>(
WrappedComponent: React.ComponentType<FormiflyContextType<T>>
): (props: React.PropsWithChildren<any>) => JSX.Element => {
return function WithFormiflyInner(props) {
export interface WithFormiflyProps extends FormiflyContextType<ObjectValidator<any>> {
}

const withFormifly = <T extends WithFormiflyProps = WithFormiflyProps>(
WrappedComponent: React.ComponentType<T>,
): (props: Omit<T, keyof WithFormiflyProps>) => React.JSX.Element => {
return function WithFormiflyInner(props: Omit<T, keyof WithFormiflyProps>) {
const context = useFormiflyContext();
return <WrappedComponent {...props} {...context}/>;
return <WrappedComponent {...props as T} {...context}/>;
};
};

Expand Down

0 comments on commit 1b1c4d0

Please sign in to comment.