[英]Pass prop to Component when using React.forwardRef
How to pass maskValue into TextMaskCustom and update mask prop .如何将 maskValue 传递给TextMaskCustom并更新mask prop 。
Basically I need to mask value to be dynamic基本上我需要掩盖价值是动态的
import { IMaskInput } from 'react-imask';
import { OutlinedInput } from '@material-ui/core';
const TextMaskCustom = React.forwardRef((props, ref) => {
const { onChange, ...other } = props;
console.log(props);
return (
<IMaskInput
{...other}
mask="0[00].0[00].0[00].0[00]"
inputRef={ref}
onAccept={(value) => onChange({ target: { name: props.name, value } })}
/>
);
});
<OutlinedInput
maskvalue="0[00].0[00].0[00].0[00]"
value={value}
onChange={onChange}
inputComponent={TextMaskCustom}
/>
Output of props Output 道具
According to https://mui.com/api/outlined-input/ you need to pass it into a specific prop called inputProps
根据https://mui.com/api/outlined-input/您需要将其传递给一个名为
inputProps
的特定道具
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.