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
Watch issues when integrating with react-number-format #572
Comments
for the phone one, can you try to use |
Could you please elaborate? I'll give it a try with |
mask inputs normally don't trigger external state updates, by trigger a re-render there is a change will reset the input to original state, i believe you may be able to solve the problem with react.memo too |
I was able to make it work with Here's the code I'm using: import React, { useCallback } from 'react';
import { RHFInput } from 'react-hook-form-input';
import t from 'prop-types';
import NumberFormat from 'react-number-format';
export default function CustomNumberFormat({ onChange, setValue, register, name, rules, mode, inputRef, ...other }) {
const onValueChange = useCallback(
values => {
onChange({
target: {
value: values.value,
},
});
},
[onChange]
);
return (
<RHFInput
register={register}
setValue={setValue}
rules={rules}
name={name}
mode={mode}
as={<NumberFormat {...other} onValueChange={onValueChange} />}
/>
);
}
CustomNumberFormat.propTypes = {
setValue: t.func.isRequired,
register: t.func.isRequired,
name: t.string.isRequired,
rules: t.object,
mode: t.oneOf(['onChange', 'onSubmit']),
onChange: t.func,
inputRef: t.any,
};
CustomNumberFormat.defaultProps = {
onChange: () => {},
mode: 'onSubmit',
rules: {},
}; |
awesome thanks for sharing the solution @hbarcelos |
More example here: |
Describe the bug
This is related to #528.
However, even following the suggested approach, it doesn't seem to work.
Whenever I
watch
a value, the input can present 2 of the following behavior:To Reproduce
Steps to reproduce the behavior:
Codesandbox link
https://codesandbox.io/s/react-number-fomat-vs-react-hook-form-broken-example-2e97y
Expected behavior
Input should work normally.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: