Preact/typeScript条件呈现“;“期望的表达”;

Preact/typeScript条件呈现“;“期望的表达”;,typescript,preact,conditional-rendering,Typescript,Preact,Conditional Rendering,您好,我只想做一个简单的条件渲染,我以前在react中做过,但在preact中似乎做不到 export const InfoSection = (props: Props) => { return ( <div> <table> <tr> <th>#</th>

您好,我只想做一个简单的条件渲染,我以前在react中做过,但在preact中似乎做不到

 export const InfoSection = (props: Props) => 
    {
        return (
            <div>
                <table>
                    <tr>
                        <th>#</th>
                        <th>User</th>
                        <th>Info</th>
                        <th>date</th>
                    </tr>
                    {
                        props.infoEntries.map( (l, i) => 
                        {
                            return (
                                <tr>
                                    <td>{i+1}</td>
                                    <td{l.UserId}</td>
                                    <td>{l.Info}</td>
                                    <td>{l.Date}</td>
                                </tr>
                            )
                        })
                    }
                    {
                        if(this.props.showEntryDetails){
                            return(
                        <tr>
                          <td>"Hello"</td>
                        </tr>
                    )
                        }
                    }
                </table>
            </div>
        )
    }
export const InfoSection=(props:props)=>
{
返回(
#
使用者
信息
日期
{
props.infoEntries.map((l,i)=>
{
返回(
{i+1}
在JavaScript中(也就是在TypeScript中),有表达式和语句。您可以将表达式用作语句,但不能将表达式用作语句

如果
是一条语句,但JSX的花括号只需要表达式。进行条件呈现的正确方法是使用
&&

{this.props.showEntryDetails && (
    <tr>
        <td>"Hello"</td>
    </tr>
)}
{this.props.showEntryDetails&&(
“你好”
)}