Skip to content

Latest commit

 

History

History
273 lines (169 loc) · 13.1 KB

CHANGELOG.md

File metadata and controls

273 lines (169 loc) · 13.1 KB

Changelog

v2.2.0 (2022-09-12)

Full Changelog

Additions:

  • Add support for persisting state #12

Merged pull requests:

v2.1.1 (2021-11-02)

Full Changelog

Closed issues:

  • useLayoutEffect warning when server side rendering #317

Merged pull requests:

2.1.0 (2021-01-13)

Full Changelog

Additions:

  • Add preact support #299

Merged pull requests:

A new major release!

That's right, a new major release jam packed full of new features and with a side helping of breaking changes.

New docs site

Technically not part of this release but definitely worth a visit to check out the new guides!

Visit the docs!

Event driven validation

Validation is now tailored to specific events (mount, blur, submit, etc).

This provides extra flexibility to tweak validation for specific scenarios - such as triggering async validation only on submit (see example below).

useField({
  validate: useCallback(({ trigger, value  }) {
    // Validation for all events
    if (!value) {
      throw Error("Value is required.");
    }

    // Validation for blur only events
    if (trigger == "blur" && value.length < 4) {
      throw Error("Value must be at least 4 characters.");
    }

    // Async validation only on submit
    if (trigger == "submit") {
      return serverSideValidation(value).then((isValid) => {
        if (!isValid) {
          throw Error("Server side validation failed");
        }
      });
    }
  }, [])
})

More info on event driven validation can be found here.

useSubmit hook

There's a new useSubmit hook which:

  • triggers the new submit validation event
  • aggregates field values into a single object
  • tracks state of async submission validation
  • guards submission logic until validation succeeds
const { isValidating, hasSubmitted, handleSubmit } = useSubmit(() => {
  console.log('This is only called if submission validation succeeds!');
});

handleSubmit(); // Trigger submission

More info on submission can be found here.

Breaking changes

  • initialValue argument on the useField hook is now required (more info)
  • validate argument on the useField hook now receives only a single argument (more info)
  • removed deprecated properties touched and initalTouched on the useField hook (more info)
  • removed initialValid and initialError arguments on the useField hook in favor of validation events (more info)
  • removed validateOnBlur, validateOnChange, and validateOnUpdate arguments on the useField hook in favor of validation events (more info)
  • removed support for returning validation errors as strings without throwing (more info)

Breaking changes

Full Changelog

v1.3.1 (2020-07-30)

Full Changelog

Fixed bugs:

  • Changes to validation arg doesn't update validation function #235

Merged pull requests:

v1.3.0 (2020-06-14)

Full Changelog

Additions:

  • Add support for providing value to onChange #41
  • Add support for React Native #35
  • Add non DOM event support to onChange #123 (andyrichardson)

Closed issues:

  • Add sitemap to docs #49
  • Update branching example to use consistent theming #47

Merged pull requests:

v1.2.1 (2020-02-25)

Full Changelog

Fixed bugs:

Closed issues:

  • Add docs for branching #26

Merged pull requests:

v1.2.0 (2020-02-05)

Full Changelog

Breaking changes:

Additions:

  • Add tracking of 'hasChanged' and 'hasBlurred' states #21

Merged pull requests:

v1.1.2 (2020-01-21)

Full Changelog

Fixed bugs:

  • Fix initial value for radio inputs #30
  • Fix initial value for checkbox inputs #28
  • Textarea onChange error #24

Closed issues:

  • Add examples for validation and conditional rendering #33
  • Add documentation for checkbox inputs #23
  • Explain how to handle submission of field values #22

Merged pull requests:

v1.1.1 (2020-01-10)

Full Changelog

Fixed bugs:

  • Handle destroy on unmount changing value #18

Merged pull requests:

v1.1.0 (2020-01-09)

Full Changelog

Breaking changes:

  • Fields without validation should be valid by default #11

Closed issues:

  • Add docs #4

Merged pull requests:

v1.0.3 (2019-12-22)

Full Changelog

Fixed bugs:

  • Error thrown when using checkboxes #6
  • No dist in published version 1.0.0 #1

Closed issues:

  • Remove unnecessary dependency "react-dom" #8

Merged pull requests:

v1.0.2 (2019-11-27)

Full Changelog