【发布时间】:2018-11-28 19:53:39
【问题描述】:
目前我正在尝试像这样使用 React 呈现信息卡:
import React from 'react'
import styled from 'styled-components';
import PropTypes from 'prop-types';
const StyledInfoCard = styled.div`
display: flex;
align-items: center;
flex-wrap: wrap;
figure {
margin: 0 1.5rem 0 0;
}
`;
const InfoCard = ({ children }) => <StyledInfoCard>{children}</StyledInfoCard>;
InfoCard.propTypes = {
children: PropTypes.string.isRequired
};
/**
* @component
*/
export default InfoCard;
子元素包含三个组件:
<InfoCard>
<Avatar alt="profile image Jonathan" source="https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"/>
<Title size='xSmall' text="Lorem ipsum dolor sit amet, consectetur adipiscing elit" />
<subTitle size='xSmall' text="Lorem ipsum dolor sit amet, consectetur adipiscing elit" />
</InfoCard>
我的目标是像这样渲染组件:
<div>
<figure>
<img .../>
</figure>
<div>
<h2>....</h2>
<h3>.....</h3>
</div>
</div>
所以子组件包含一个包装器,除了<avatar> 组件
有什么想法吗?
【问题讨论】:
标签: reactjs