JavaScript/react/条件渲染:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第13行: 第13行:
function render() {
function render() {
   return condition ? <Component /> : null;
   return condition ? <Component /> : null;
}</syntaxhighlight>
== && ==
<syntaxhighlight lang="javascript">
function render() {
  return condition && <Component />;
}</syntaxhighlight>
}</syntaxhighlight>

2022年6月8日 (三) 11:07的版本

引言

IF/ELSE

function render() {
  if (condition) return <Component />;
  else return null;
}

三目运算符

function render() {
  return condition ? <Component /> : null;
}

&&

function render() {
  return condition && <Component />;
}