final-form / final-form/react-final-form

useFieldSubscription

Open
#808 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.4k
Forks
497
PR merge metrics
No merged PRs in 30d

Description

### 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` or `useField` would be used with some "real" DOM element.
- `onFocus` accepts FocusEvent
- `onBlur` accepts BlurEvent
- `onChange` accepts ChangeEvent

That'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:
- a credit card from - that's many inputs, which act as one (for the form)
- a "pin input", where every digit is a separate input, but that's no more than a "design" decision, and for the Form it still could be one.
- smart file pickers, which are not able to properly fire `onChange` event, as long as are controlled by themselves.

### What is the expected behavior?

A good solution would be a `useFieldSubscription` hook (which `useField` could use underneath), to provide a real "low level" API to the `final-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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.