Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Add hook for parent component to be notified when input value changes #932
Conversation
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

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

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
MaskedInputinside aFormikform. When themaskprop toMaskedInputchanges, it can change the value of the input element and leave the value stored inFormikstale. With thisonSetInputValuehook prop, we can provide a function that syncs theFormikstate (viasetFieldValue) when thevaluein 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.