JavaScript/react/条件渲染:修订间差异
来自康健生活
< JavaScript | react
| 第6行: | 第6行: | ||
if (condition) return <Component />; | if (condition) return <Component />; | ||
else return null; | else return null; | ||
}</syntaxhighlight> | |||
== 三目运算符 == | |||
<syntaxhighlight lang="javascript"> | |||
function render() { | |||
return condition ? <Component /> : null; | |||
}</syntaxhighlight> | }</syntaxhighlight> | ||
2022年6月8日 (三) 11:06的版本
引言
IF/ELSE
function render() {
if (condition) return <Component />;
else return null;
}
三目运算符
function render() {
return condition ? <Component /> : null;
}
No categories