亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將我的代碼轉換為正確的 jsx 格式?

如何將我的代碼轉換為正確的 jsx 格式?

開心每一天1111 2022-07-08 16:16:20
我是 Reactjs 的新手。這是我的代碼。我希望 Link 組件只包裝 Card 組件。但是當我的代碼是這樣的時候,reactjs 讓我失望了。我怎樣才能正確編寫這些代碼?const ImageFrame = ({ movieId, movieName, searchWord, image, personMovieId, clickable, clearFavouriteMovie }) => {return (        <div className = "col-sm-3 mt-5 animated fadeInLeftBig ">            { clickable ? /* if clickable props is true --> go movie, else go movie again but with personal movie id ! */                 <Link to={{ pathname:`/movie/${movieId}`, movieName: `${movieName}`, searchWord: `${searchWord}` }}>                    <Card className = "card-box image-frame  ">                        <Card.Img variant="top" src={image} alt="movieImg" />                    </Card>                    </Link> **!!! I WANT Link component stays here !!!**                     {                         clearFavouriteMovie && <button                            className = "mt-3 btn btn-warning"                            onClick = { () => clearFavouriteMovie(movieId)}                        > Bu Filmi Sil </button>                     }                :                 <Link to = {{pathname: `/movie/${personMovieId}`}}>  {/* Person Known For Movies*/}                <Card className = "bg-dark text-light card-box  image-frame " style = {{maxHeight: "500px"}}>                    <Card.Img variant="top" src={image} alt="movieImg" />                </Card>                </Link>            }                    </div>    )
查看完整描述

1 回答

?
莫回無

TA貢獻1865條經驗 獲得超7個贊

if 語句只能返回一個元素,在這種情況下,您嘗試返回兩個<Link>并將<button>其合并為一個使用 a<React.fragment>


例子


const ImageFrame = ({ movieId, movieName, searchWord, image, personMovieId, clickable, clearFavouriteMovie }) => {


return (

        <div className = "col-sm-3 mt-5 animated fadeInLeftBig ">

            { clickable ? /* if clickable props is true --> go movie, else go movie again but with personal movie id ! */

                 <React.fragment>

                 <Link to={{ pathname:`/movie/${movieId}`, movieName: `${movieName}`, searchWord: `${searchWord}` }}>

                    <Card className = "card-box image-frame  ">

                        <Card.Img variant="top" src={image} alt="movieImg" />

                    </Card>

                    </Link> **!!! I WANT Link component stays here !!!** 

                    { 

                        clearFavouriteMovie && <button

                            className = "mt-3 btn btn-warning"

                            onClick = { () => clearFavouriteMovie(movieId)}

                        > Bu Filmi Sil </button> 

                    }

                </React.fragment>

                : 

                <Link to = {{pathname: `/movie/${personMovieId}`}}>  {/* Person Known For Movies*/}

                <Card className = "bg-dark text-light card-box  image-frame " style = {{maxHeight: "500px"}}>

                    <Card.Img variant="top" src={image} alt="movieImg" />

                </Card>

                </Link>

            }            

        </div>

    )


查看完整回答
反對 回復 2022-07-08
  • 1 回答
  • 0 關注
  • 204 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號