0

Took this component from MUI docs

export interface CustomProps {
    onChange: (event: { target: { name: string; value: string } }) => void;
    name: string;
}
  const NumberFormatCustom = React.forwardRef<NumberFormat, CustomProps>(
  function NumberFormatCustom(props, ref) {
    const { onChange, ...other } = props;

    return (
      <NumberFormat
        {...other}
        getInputRef={ref}
        onValueChange={(values) => {
          onChange({
            target: {
              name: props.name,
              value: values.value,
            },
          });
        }}
        thousandSeparator
        isNumericString
        prefix="$"
      />
    );
  },
);

then it is used like this

      <TextField
        label="react-number-format"
        value={values.numberformat}
        onChange={handleChange}
        name="numberformat"
        id="formatted-numberformat-input"
        InputProps={{
          inputComponent: NumberFormatCustom as any, //Here
        }}
        variant="standard"
      />

Now the question is how do I pass props to NumberFormat? How can I even use it <NumberFormatCustom name='???' onChange={???}></NumberFormatCustom>

2
  • did you tried InputProps ={{inputComponent: <NumberFormatCustom name='???' />}} ? Commented Jan 26, 2022 at 11:31
  • Yes, but I need also to pass onChange prop and I have no idea what I need to pass in it Commented Jan 26, 2022 at 12:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.