JavaScript/react/条件渲染
来自康健生活
< JavaScript | react
引言
IF/ELSE
function render() {
if (condition) return <Component />;
else return null;
}
三目运算符
function render() {
return condition ? <Component /> : null;
}
&&
function render() {
return condition && <Component />;
}
某些场景下
condition = false 是,会将 false 以字符串形式输出到页面中。IIFE
function render() {
return <>
{
(() => (condition ? <Component /> : null))();
}
</>;
}
No categories