Skip to content

Releases: akuzko/re-use-form

v3.5.1

24 Sep 15:18
Compare
Choose a tag to compare

Patch Description:

  • Fixed getError helper returned by usePartial hook. There was a flaw in useCallback's dependencies used for this function resulted in initial empty errors to forever stay in function's closure, forcing it it return undefined errors all the time. Thanks to @MrFreemind for reporting this bug.

v3.5.0

24 Sep 13:12
Compare
Choose a tag to compare

New Features

  • Added ability to pass a function to reset form helper. When passed, it will be called with current form attributes, and it's return value will be assigned as next form attributes. This behaviour can be used to amend current "clean" form attributes in some way without affecting form's isPristine flag.
  • Added setState form helper. Designed for advanced usage, it takes an updater function and passes whole form's state to it. It's return value is assigned as next entire form state.

v3.4.0

23 Sep 22:13
Compare
Choose a tag to compare

New Features

  • Added ability to pass function as an argument to form's set helper method. This function takes form attributes as it's only argument and should return an object with updates to be made. This behavior can be used to avoid dependency on attrs (that is the most common thing to change) in component hooks, such as useCallback.

v3.3.0

22 Sep 20:50
Compare
Choose a tag to compare

New Features

  • Added isPristine boolean helper flag. true initially, it indicates whether or not form attributes were changed or touched in any way. Calling reset helper function also sets it value to true.

v3.2.1

22 Sep 13:07
Compare
Choose a tag to compare

Patch Description

  • Fixed bug related with initialization of controlled form with no auxiliary config prop.

v3.2.0

17 Sep 21:02
Compare
Choose a tag to compare

Release Description

  • Added support for controlled behavior for dedicated form hook FormProvider component:
function OrderEditor() {
  const [attrs, setAttrs] = useState(initial);

  const fillForm = useCallback(() => {
    setAttrs({
      username: 'Guest',
      address: 'Home'
    });
  }, []);

  return (
    <>
      <FormProvider attrs={attrs} onChange={setAttrs}>
        <OrderForm />
      </FormProvider>
      <button onClick={fillForm}>Prefill form</button>
    </>
  );
}

v3.1.0

29 Mar 15:07
Compare
Choose a tag to compare

New Features

  • setError and setErrors helpers now return a promise that is resolved with errors object when errors are rendered. This feature can be used to react on errors after they've been set, for instance, scroll to one of them if needed.

v3.0.0

11 Mar 23:31
Compare
Choose a tag to compare

Breaking Changes

  • All form hooks now accept single config object with strict structure as their only argument.
  • Changed custom onChange handler API: custom handler now accepts input value as it's first argument, and the rest of properties, including input name, are passed as second options argument.
  • useMoreValidations hook has been dropped in favor of new useConfig hook.

New Features

  • useConfig hook can be used to dynamically add additional configuration to the form.
  • Added makeForm helper to declare dedicated form hooks for building advanced and well-organized forms.

v2.8.1

10 Mar 21:53
Compare
Choose a tag to compare

Patch Description

  • Fixed validation of stand-alone inputs with complex paths (i.e. ones that represent nested attributes), for instance: validate('foo.bar.baz');

v2.8.0

22 Feb 21:30
Compare
Choose a tag to compare

Release Description

  • Added useMoreValidations experimental helper hook that can be used to add optional validation in runtime. Look README or example app for usage examples.