【发布时间】:2021-10-27 01:14:20
【问题描述】:
有一个名为“checkPwd”的变量有 3 个可选值。 “正确”、“空”和“无效” return 方法应基于此变量返回各种 HTML 元素。 像这样。
<FormControl>
<Stack style={styles.stack}>
<Input
type="password"
placeholder="Confirm Password"
isInvalid={checkPwd == "correct" ? false : true}
/>
{
if (checkPwd == "empty") {
<FormControl.ErrorMessage>
Please confirm password.
</FormControl.ErrorMessage>
} else if(checkPwd == "invalid") {
<FormControl.ErrorMessage>
Password is not strong enough.
</FormControl.ErrorMessage>
}
}
</Stack>
</FormControl>
但此代码在编译时出现错误。 我希望你的友好合作。
【问题讨论】:
-
这能回答你的问题吗? if-else statement inside jsx: ReactJS
标签: javascript reactjs react-native jsx