[英]How to conditionally add a property in jsx
I have a simple material UI RadioGroup code which i want to display conditionally in row and column, default mode is column, Below is my code我有一个简单的材料 UI RadioGroup 代码,我想在行和列中有条件地显示它,默认模式是列,下面是我的代码
<RadioGroup
aria-label="gender"
name="gender1"
value={value}
onChange={handleChange}
>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
<FormControlLabel value="other" control={<Radio />} label="Other" />
</RadioGroup>
Now in order to display it in row, i need to add one poperty row
at RadioGroup
like below现在为了按行显示它,我需要在
RadioGroup
添加一个 poperty row
,如下所示
<RadioGroup
row
aria-label="gender"
name="gender1"
value={value}
onChange={handleChange}
>
How can i just update one line conditionally?我怎样才能有条件地更新一行? Here is codesandbox link
这是代码和框链接
Create an isRow
state and use it's value to conditionally render RadioGroup as row or otherwise创建一个
isRow
状态并使用它的值有条件地将 RadioGroup 呈现为行或其他方式
const [isRow, setIsRow] = useState(true);
<RadioGroup
row={this.state.isRow}
aria-label="gender"
name="gender1"
value={value}
onChange={handleChange}
>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.