Open dy opened 4 years ago
// similar to settings-panel
const params = [{ id: 'number', type: Number }]
const params2 = { number: 3, ... }
const [ fields, { set, submit, validate, reset } ] = useForm( params )
const { fieldName: { valid, error, touched, ref, type, validate }, ...rest } = fields
const [ { value, error, touched, ref, input }, { validate, set } ] = useField( 'name', { type: Number, validate: (value) => {} } )
react-table introduces nice useTable hook approach, able to generate props for target elements. Same technique can be used here.
3 aspects of useFormFIeld
.
Possibly unnecessary separation of useFormField
and useInput
: separates creation of some data from accessing - not conceptually very much different.
useValidation
can be a part of functionality, augmenting useInput
. (although it redefines onChange
, which may be redundant.
Passing input props into hook, instead of direct element is doubtful practice. It's better to focus on direct generating the UI, instead of passing props through some transforms.
useValidation
is insufficient on itself: it must show error only when the input is blurred, not when focused, so it depends on input element state.
Also, we may want to validate on form submit for example, but validate requires value to check against, since it is not bound to specific input - therefore it is useful to have something that knows about "input store".
So, responding to 1, 2, 3.
field.validate()
is better.The quesion is: how to use useFormField
as aspect, considering that it may create an input?
This is very similar to useStore(id, initObj)
- if id is not found, it is created..
There can therefore be useFormField(id|element, initProps)
.
Conceptually, that is similar to upsert proposal: upsert(id, update: oldValue => newValue, insert: () => initValue)
, but in case of hooks update
and insert
functions are single init
function.
More generally, resource hook creates a thread (like in erlang) of specific functionality (specific lens to look at data source).
To overcome explicit createStore
call, there must be main aspect and auxiliary aspects - main aspect creates/controls entry, aux augments behavior.
Reference implementations
formal
react-hook-form
register
?handleSubmit
is returned? Is thatsend
orafter send
or what?react-use-form-state
useFormField
is not exposed - constructors returned fromuseForm
play role of them - overkill.react-use-formless
react-final-form-hooks
handleSubmit
and why? Redux-form legacy?formik
useTable
hooked-form
formee