The Wayback Machine - https://web.archive.org/web/20201204093047/https://github.com/text-mask/text-mask/pull/932
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hook for parent component to be notified when input value changes #932

Open
wants to merge 1 commit into
base: master
from

Conversation

@ericfreese
Copy link

@ericfreese ericfreese commented May 2, 2019

Text mask component directly modifies the input element's dom value. This commit adds a hook prop that can be used to notify parent components when the input's value changes so that they can update their own state to reflect the new value in the dom.

This came up for me when using MaskedInput inside a Formik form. When the mask prop to MaskedInput changes, it can change the value of the input element and leave the value stored in Formik stale. With this onSetInputValue hook prop, we can provide a function that syncs the Formik state (via setFieldValue) when the value in the dom is changed.

Repro here: https://codesandbox.io/embed/l7or5346wq

Looking for feedback on general approach, naming, etc. Then I'll add documentation and tests as needed.

Text mask component directly modifies the input element's dom `value`.
This commit adds a hook prop that can be used to notify parent
components when the input's value changes so that they can update their
own state to reflect the new value in the dom.

This came up for me when using `MaskedInput` inside a `Formik` form.
When the `mask` prop to `MaskedInput` changes, it can change the value
of the input element and leave the value stored in `Formik` stale. With
this `onSetInputValue` hook prop, we can provide a function that syncs
the `Formik` state (via `setFieldValue`) when the `value` in the dom is
changed.

Repro here: https://codesandbox.io/embed/l7or5346wq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant
You can’t perform that action at this time.