JavaScript/react/条件渲染:修订间差异
来自康健生活
| 第76行: | 第76行: | ||
== switch == | == switch == | ||
<syntaxhighlight lang="javascript"> | |||
function render() { | |||
return <> | |||
{ | |||
(()=> { | |||
switch (condition) { | |||
case 1: return <Component1 />; | |||
case 2: return <Component2 />; | |||
default: null; | |||
} | |||
})() | |||
} | |||
</>; | |||
}</syntaxhighlight> | |||