1. import React,{FC} from "react"
    2. type IProps ={
    3. flag:boolean
    4. }
    5. const Show:FC<IProps>=(props)=>{
    6. {
    7. if(props.flag){
    8. return <div>已经登陆</div>
    9. }
    10. else{
    11. return <div>未登录</div>
    12. }
    13. }
    14. }
    15. export default Show
    1. import React from 'react';
    2. import ReactDOM from 'react-dom';
    3. import './index.css';
    4. import * as serviceWorker from './serviceWorker';
    5. import Show from "@/components/show"
    6. let user={
    7. name:"张三",
    8. age:18
    9. }
    10. ReactDOM.render(
    11. <Show flag={true}></Show>,
    12. document.getElementById('root')
    13. );
    14. serviceWorker.unregister();

    可以使用&&进行条件渲染

    1. const Show:FC<IProps>=(props)=>{
    2. {
    3. return <div>
    4. {props.flag&&<div>已经登录</div>}
    5. </div>
    6. }
    7. }