Comparing version 2.1.8 to 2.1.9
@@ -32,2 +32,3 @@ import Field, { FieldOpts, Validator } from './Field'; | ||
constructor(opts: FormOpts<FieldValues>); | ||
private _attachFields; | ||
attachFields(fieldOpts: FormFieldOpts<FieldValues> | Partial<FormFieldOpts<FieldValues>>): void; | ||
@@ -34,0 +35,0 @@ detachFields(fieldNames: Array<keyof FieldValues>): void; |
@@ -67,5 +67,5 @@ var __assign = (this && this.__assign) || function () { | ||
this._events = new Events(); | ||
this.attachFields(this.opts.fields); | ||
this._attachFields(this.opts.fields); | ||
} | ||
Form.prototype.attachFields = function (fieldOpts) { | ||
Form.prototype._attachFields = function (fieldOpts) { | ||
var _this = this; | ||
@@ -91,2 +91,6 @@ var fieldNames = Object.keys(fieldOpts); | ||
}; | ||
Form.prototype.attachFields = function (fieldOpts) { | ||
this._attachFields(fieldOpts); | ||
this._events.dispatch('attach fields'); | ||
}; | ||
Form.prototype.detachFields = function (fieldNames) { | ||
@@ -97,2 +101,3 @@ var _this = this; | ||
}); | ||
this._events.dispatch('detach fields'); | ||
}; | ||
@@ -99,0 +104,0 @@ Form.prototype.setState = function (values) { |
@@ -1,7 +0,20 @@ | ||
import { useMemo } from 'react'; | ||
import { useMemo, useState, useEffect } from 'react'; | ||
import Form from './Form'; | ||
var useForm = function (opts, deps) { | ||
return useMemo(function () { return new Form(opts); }, deps || []); | ||
var _a = useState(0), v = _a[0], update = _a[1]; | ||
var form = useMemo(function () { return new Form(opts); }, deps || [v]); | ||
useEffect(function () { | ||
var handleFormUpdates = function () { | ||
update(function (v) { return ++v; }); | ||
}; | ||
form.on('attach fields', handleFormUpdates); | ||
form.on('detach fields', handleFormUpdates); | ||
return function () { | ||
form.off('attach fields', handleFormUpdates); | ||
form.off('detach fields', handleFormUpdates); | ||
}; | ||
}, []); | ||
return form; | ||
}; | ||
export default useForm; | ||
//# sourceMappingURL=useForm.js.map |
{ | ||
"name": "formular", | ||
"version": "2.1.8", | ||
"version": "2.1.9", | ||
"author": "Pavel Ivanov", | ||
@@ -5,0 +5,0 @@ "description": "Build forms in React. Easy-Peasy!", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
81067
1260