React中可重用的TextField [英] Reusable TextField in React
本文介绍了React中可重用的TextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在React的Material UI中使用了可重用的TextField,并且在使用条件时遇到了问题.如果没有传递 InputLabelProps
,我就不必使用它.
I'm using a reusable TextField in Material UI in React and i have a problem using a condition. I need not to use InputLabelProps
if it isnt passed on to it.
请在下面检查我可重复使用的TextField
Pls check my reusable TextField below
<TextField
fullWidth
type={prop.type}
label={prop.label}
name={prop.name}
variant="outlined"
value={prop.value}
onChange={prop.handleChange}
onBlur={prop.onBlur}
helperText={prop.helperText}
error={prop.error}
{prop.InputLabelProps ? InputLabelProps={{
shrink: prop.InputLabelProps,
}} : ''}
/>
推荐答案
如果不存在,只需将其设置为undefined:
Just set it to undefined if it's not present:
InputLabelProps={prop.InputLabelProps ? { shrink: prop.InputLabelProps } : undefined}.
在大多数情况下,如果将prop设置为undefined,它将表现为您根本没有通过它
If you set a prop to undefined in most cases it'll act like you didn't pass it at all
这篇关于React中可重用的TextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文