Releases: moubi/enform
Subsequent form value updates
It's now possible to have several onChange()
calls that update form values without skipping or erasing.
<input
type="text"
value={values.field1}
name="field1"
onChange={e => {
onChange("field1", e.target.value);
onChange("field2", e.target.value);
}}
/>
The above snippet will change both field values successfully.
Drop IE11 (with core-js) support
Drop IE11 support in babel.config.js
. This change no longer require core-js
to be present in the consumer project as a polyfil fallback.
Introduce useEnform() hook
<Enform />
now uses theuseEnform
hook internally.useEnform
exposes the same API as the render props component.- can be used like so:
import { useEnform } from "enform";
const { values, errors, ... } = useEnform(initialValuesObject, validationObject);
- no breaking changes
- no changes in the bundle size
Add IE11 support
- Add IE11 support
- update babel config with the following
- ensure polyfills are loaded just once
- transpile modules to commonjs in tests
Default passing validation to false
If field value is passing its validation the errors
object for that field will always default to false
. With that in place it is no longer required for validator functions to return falsy
value. The should only return error message or true
.
Cache internal functions with useCallback
Introduce useCallback
to cache functions exposed by Enform.
Set errors programmatically
- ✅ create
setErrors()
function to allow setting errors from outside Enfrom.
This feature should cover use cases where errors need to be set as a result on non user input. Fx. calling an API that returns field specific error. - 🔨 Do not call
setErrors()
internally if error is not present for a field when usingonChange()
.
Deep compare initial values using sort and JSON.stringify
Check for changes in the initial
prop using JSON.stringify
and key sorting
😮That guarantees high chance of success without introducing external dependencies.
Handle re-render when initial prop changes
Enform will now re-render when initial
prop updates ✅ That is done using ref comparison, so a new object should be passed down to Enform in order to make it update its state.
Remove react and react-dom from dependencies
They are now moved to devDependencies
and "react": ">= 16.8.0"
(hooks ↪️) goes to peerDependencies
.
As a consequence the package bundle should be smaller.