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

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第76行: 第76行:


== switch ==
== switch ==
<syntaxhighlight lang="javascript">
function render() {
  return <>
    {
      (()=> {
        switch (condition) {
          case 1: return <Component1 />;
          case 2: return <Component2 />;
          default: null;
        }
      })()
    }
  </>;
}</syntaxhighlight>