Skip to content

Commit

Permalink
Merge pull request #6 from charjac/CHORE/TYPINGS
Browse files Browse the repository at this point in the history
add ts typings
  • Loading branch information
amazingandyyy committed Jul 17, 2019
2 parents 087ac70 + 7da7d66 commit 2b48d5b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
declare module 'use-form-react' {
import React from 'react';
export type ValidationFunc<Fields> = (fields: Fields) => string | undefined;

export interface UseFormConfig<Fields extends Record<string, any>> {
initialValues?: Partial<Fields>;
validation?: Partial<Record<keyof Fields, ValidationFunc<Fields>>>;
debug?: boolean;
callback?: (inputs: Fields)=> void;
}

export interface UseFormState<Fields> {
onSubmit: (event: React.SyntheticEvent<HTMLFormElement>) => void,
onChange: (event: React.SyntheticEvent<HTMLInputElement>) => void,
inputs: Fields,
submitting: boolean,
dirty: boolean,
reset: () => void,
setInputs: (fields: Fields) => void,
errors: Record<keyof Fields, string>,
valid: boolean,
}

const useForm: <Fields = any>(name: string, config: UseFormConfig<Fields>) => UseFormState<Fields>;

export default useForm;
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"type": "git",
"url": "https://github.com/amazingandyyy/use-form-react.git"
},
"types": "index.d.ts",
"peerDependencies": {
"react": "^16.8.0"
},
Expand All @@ -25,6 +26,7 @@
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@babel/preset-react": "^7.0.0",
"@types/react": "^16.8.18",
"babel-jest": "^24.7.1",
"jest": "^24.7.1",
"parcel-bundler": "^1.12.3",
Expand Down

0 comments on commit 2b48d5b

Please sign in to comment.