[英]How to use a React component as options of Form.Select in React-Bootstrap
I'm implementing a Form.Select that should have another react component as its options.我正在实施一个Form.Select ,它应该有另一个反应组件作为其选项。
Here, the name of the Form.Select is "Collection" and its options should be a card component (with an image) called "CollectionCard".在这里, Form.Select的名称是“Collection”,它的选项应该是一个名为“CollectionCard”的卡片组件(带有图像)。
This is the expected implementation.这是预期的实施。 https://i.stack.imgur.com/8yWZ3.png (Refer this image)
https://i.stack.imgur.com/8yWZ3.png (参考这张图片)
And, here is my current code.而且,这是我当前的代码。
<Form.Group controlId="form.collection">
<Form.Label className="fw-bold">Collection</Form.Label>
<Form.Select className="mb-5" aria-label="Collection">
<option value="1">
<CollectionCard />
</option>
<option value="2">
<CollectionCard />
</option>
</Form.Select>
</Form.Group>
But this is how it actually shows in the UI with the above code.但这是上面代码在 UI 中实际显示的方式。 https://i.stack.imgur.com/eI8hv.png (Refer this image)
https://i.stack.imgur.com/eI8hv.png (参考这张图片)
The "CollectionCard" component is not getting rendered inside the Form.Select and it shows as [object Object] . “CollectionCard”组件未在Form.Select内呈现,它显示为[object Object] 。
Updated I tried adding {} for the "CollectionCard" as well,更新后我也尝试为“CollectionCard”添加 {},
<option value="2">
{<CollectionCard />}
</option>
Still not working.还是行不通。
Updated Adding CollectionCard component code below.更新了下面的添加 CollectionCard 组件代码。
import React from 'react';
import './CollectionCard.scss';
import {Card} from 'react-bootstrap';
export const CollectionCard: React.FC = (props) => {
return (
<div className="collection-card">
<Card className="d-flex flex-row border-0 bg-transparent">
<Card.Img className="card-img-xs" src={require('../../../../assets/nft-sample.png')} alt="img" />
<Card.Body className="p-0 ms-3 align-self-center">
Lorep Ipsum
</Card.Body>
</Card>
</div>
)
}
Please help me to get this resolved.请帮我解决这个问题。 Thanks!
谢谢!
just set your component inside of bracket只需将您的组件设置在括号内
<Form.Group controlId="form.collection">
<Form.Label className="fw-bold">Collection</Form.Label>
<Form.Select className="mb-5" aria-label="Collection">
<option value="1">
{<CollectionCard />}
</option>
<option value="2">
{<CollectionCard />}
</option>
</Form.Select>
</Form.Group>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.