【发布时间】:2020-04-04 01:55:03
【问题描述】:
我有一个只有在有文本时才会呈现的组件。我正在尝试为我创建的卡片 div 创建标题 div,但标题 div 未正确呈现。
FeedCardHeader.js
import React from 'react';
import styled from 'styled-components/native';
import { Text } from 'react-native'
const Root = styled.View`
height 50;
flex-direction: row;
align-items: center;
justify-content: center;
background-color: blue;
`;
function FeedCardHeader() {
return(
<Root>
<Text>This is a text</Text>
</Root>
)
}
export default FeedCardHeader;
FeedCard.js
import React from 'react';
import styled from 'styled-components/native';
import FeedCardHeader from './FeedCardHeader';
const Root = styled.View`
min-height: 180px;
background-color: white;
width: 100%;
shadow-color: ${props => props.theme.SECONDARY};
shadow-offset: 0px 2px;
shadow-radius: 2px;
shadow-opacity: 0.1;
elevation: 2;
`;
function FeedCard() {
return (
<Root>
<FeedCardHeader />
</Root>
);
}
export default FeedCard;
我的主要问题是,如果 <Text>This is a text</Text> 不存在,则不会呈现组件。当它在那里时,它只是组件中内容的大小。我将组件的高度设置为 50,所以它不应该在那里并且具有设置的高度。
【问题讨论】:
标签: javascript css react-native