Skip to content

Commit 4078423

Browse files
authored
Merge pull request #11 from balavishnuvj/fix/form-error-undefined
fix: undefined formErrors
2 parents 727c52f + 861629c commit 4078423

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/use-form.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,14 @@ export default function useNewForm(fieldConfig) {
228228
return formValues[fieldName];
229229
},
230230
get errorMsg() {
231-
return formErrors[fieldName].errorMsg;
231+
return formErrors[fieldName]?.errorMsg ?? '';
232232
},
233233
get isValid() {
234-
return formErrors[fieldName].isValid;
234+
/**
235+
* Validation happens async, so there is a possibility that `formErrors[fieldName]` is not defined yet.
236+
* So by default, for that duration isValid is false
237+
*/
238+
return formErrors[fieldName]?.isValid ?? false;
235239
},
236240
};
237241
});

0 commit comments

Comments
 (0)