Open theKashey opened 4 years ago
Surely it would be called useFieldSubscription
, right?
What is the shape of what it returns?
π
sure it's about field, and the shape is the same as useField
, just without "react taste"
export type FieldSubscriptionProps<T=string> = {
name: string,
onBlur: () => void,
onChange: (?T) => void,
onFocus: () => void,
value: any,
type?: string,
checked?: boolean,
multiple?: boolean
}
export type FieldSubscriptionRenderProps = {
input: FieldSubscriptionProps,
meta: {
/* is the same */
}
}
In this case useField
could utilise useFieldSubscription
and just shadow onChange
with the own "event payload unwrapper".
Are you submitting a bug report or a feature request?
Feature request
What is the current behavior?
The current expectation, not a behaviour, is that
Field
oruseField
would be used with some "real" DOM element.onFocus
accepts FocusEventonBlur
accepts BlurEventonChange
accepts ChangeEventThat's working for the majority of cases, but not for all. For example, I could have a "composite" input without a fully "DOM-compatible" on change event:
onChange
event, as long as are controlled by themselves.What is the expected behavior?
A good solution would be a
useFieldSubscription
hook (whichuseField
could use underneath), to provide a real "low level" API to thefinal-form
, without all the React and DOM sugar added by this package, but still with a proper initialization.π
useFieldSubscription
is already written, here it is - https://github.com/final-form/react-final-form/blob/master/src/useField.js#L53-L131 It just has to be extracted to a separate hook.