reactjsresponsiveantdcard

Add Icon and Title on the card header in antd


I am trying to add header and an icon in antd responsive cards, but not able to add and find any solution to it, can any one help me with this since, i am very new to this i am not able to figure it out

const data = [
{
title: 'Title 1',
},
{
title:  <SearchOutlined />'Title 2',
},
];

ReactDOM.render(
<List
grid={{
gutter: 16,
xs: 1,
sm: 2,
md: 4,
lg: 4,
xl: 6,
xxl: 3,
}}
dataSource={data}
renderItem={item => (
<List.Item>
<Card title={item.title}>Card content</Card>
</List.Item>
)}
/>,
document.getElementById('container'),
);

Solution

  • You are close. Just enclose the title content with react fragment

    const data = [
      {
        title: "Title 1",
        content: (
          <div>Content 1</div>
        )
      },
      {
        title: (
          <>
            <SearchOutlined /> Title 2
          </>
        ),
        content: (
           <div>Content 2</div>
        )
      }
    ];
    
    <List
        dataSource={data}
        renderItem={item => (
            <List.Item>
               <Card title={item.title}>{item.content}</Card>
            </List.Item>
         )}
    />