我想有条件地在输入类型上添加道具,我想检查是否input_key
是数字,如果是,我想添加min_max
道具,因为我不希望它添加任何类型
const min_max = {
min: 0,
max: 100
};
<Input
type={type}
name={input_key}
id={input_key}
{input_key === 'number' && ...min_max}
required={required}
placeholder={placeholder}
/>
我如何通过使用这样的传播使其工作?
您可以利用三元条件
<Input
type={type}
name={input_key}
id={input_key}
{...(input_key === 'number'? min_max: {})}
required={required}
placeholder={placeholder}
/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句