File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " use-validation-react" ,
3- "version" : " 1.0.3 " ,
3+ "version" : " 1.0.4 " ,
44 "description" : " a lightweight react library for hook-based declarative form validation" ,
55 "main" : " ./lib/cjs/index.js" ,
66 "module" : " ./lib/esm/index.js" ,
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ export type UseValidationReturnType<T> = {
1313 validateAll : ( form : T ) => Promise < Record < keyof T , ValidationResultType > > ;
1414 validateFormElement : ( form : T , elementKey : keyof T ) => Promise < void > ;
1515 clearValidations : ( ) => void ;
16+ isElementValid : ( elementKey : keyof T ) => boolean
1617} ;
1718
1819export const useValidation = < T > (
@@ -60,12 +61,20 @@ export const useValidation = <T>(
6061 setValidationResult ( { } as Record < keyof T , ValidationResultType > ) ;
6162 } , [ ] ) ;
6263
64+ const isElementValid = useCallback ( ( elementKey : keyof T ) => {
65+ if ( ! validationResult [ elementKey ] ) {
66+ return true ;
67+ }
68+ return validationResult [ elementKey ] . isValid ;
69+ } , [ validationResult ] ) ;
70+
6371 return {
6472 validationResult,
6573 isValidated,
6674 isFormValid,
6775 validateAll,
6876 validateFormElement,
6977 clearValidations,
78+ isElementValid,
7079 } ;
71- } ;
80+ } ;
You can’t perform that action at this time.
0 commit comments