import React,{FC} from "react"
type IProps ={
flag:boolean
}
const Show:FC<IProps>=(props)=>{
{
if(props.flag){
return <div>已经登陆</div>
}
else{
return <div>未登录</div>
}
}
}
export default Show
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import * as serviceWorker from './serviceWorker';
import Show from "@/components/show"
let user={
name:"张三",
age:18
}
ReactDOM.render(
<Show flag={true}></Show>,
document.getElementById('root')
);
serviceWorker.unregister();
可以使用&&进行条件渲染
const Show:FC<IProps>=(props)=>{
{
return <div>
{props.flag&&<div>已经登录</div>}
</div>
}
}