Skip to content

0.9.1

Compare
Choose a tag to compare
@wsmd wsmd released this 27 Apr 23:18
· 46 commits to master since this release

✨ 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! πŸ™‡β€β™‚οΈ