0.9.1
β¨ Improvements
Added Typings for state.errors
In 0.9.0, react-use-form-state
added ability to specify custom validation errors. With this release, it's possible to add additional type safety to those custom errors retrieved via state.errors
.
interface I18nError {
en: string;
fr: string;
}
interface FormFields {
username: string;
password: string;
}
interface FormErrors {
username?: I18nError;
password?: string;
}
const [formState, input] = useFormState<FormFields, FormErrors>();
formState.errors.username; // Will be undefined, or I18nError
Further reading:
π Bug Fixes
Stricter Type Safety for State Keys
When working with TypeScript, types of values
, validity
, touched
and errors
are now stricter, which means attempts to accessing properties that don't exists on these objects will result in an error at build time.
interface FormFields {
username: string;
password: string;
}
const [formState, input] = useFormState<FormFields>();
formState.fieldThatDoesNotExists // will throw a compiler error
π¦ Other Changes
- Proofread README.md file (#58)
A special thanks to all the contributors that helped make this release possible! πββοΈ