reactjs - React 中的可重用文本字段
问题描述
我在 React 的 Material UI 中使用了可重用的 TextField,但我在使用条件时遇到了问题。InputLabelProps
如果它没有传递给它,我不需要使用它。
请在下面检查我的可重复使用的 TextField
<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,
}} : ''}
/>
解决方案
您可以通过在三元运算符之前添加条件语句来实现此目的,
{prop.InputLabelProps && prop.InputLabelProps ? InputLabelProps={{
shrink: prop.InputLabelProps,
}} : ''}
推荐阅读
- c# - 如何在 Windows 窗体上动态绘制图像?
- kubernetes - 如何将 GKE 的集群自动扩缩器日志导出到外部日志服务?
- javascript - 如何在Javascript中保持复选框的状态
- sql - SQL - 从连接两个表中获得结果的最快算法
- animation - FFmpeg:如何为每张视频幻灯片使用多个图像,并且动画/放大/缩小/淡化每个图像只有一个?
- ios - 如何执行 LinkingObject 的迁移?
- sublimetext3 - 如何在 Sublime Text 3d 中选择所选文本的上一个实例
- git - 如何从 Perforce 缓慢迁移到 Git
- php - 根据 Wordpress 用户对象中的数据创建带有指向页面的动态链接的按钮
- python - re.sub 具有相同字符串的不同答案跨行拆分