JavaScript/react/条件渲染:修订间差异
来自康健生活
| 第91行: | 第91行: | ||
</>; | </>; | ||
}</syntaxhighlight> | }</syntaxhighlight> | ||
== Enums objects == | |||
<syntaxhighlight lang="javascript"> | |||
const Components = Object.freeze({ | |||
save: <Component1 />, | |||
edit: <Component2 /> | |||
}); | |||
function render() { | |||
const action = condition ? "save" : "edit": | |||
return <> | |||
{Components(action))} | |||
</>; | |||
} | |||
</syntaxhighlight> | |||