【发布时间】:2020-07-12 02:55:02
【问题描述】:
我想将父组件 Card 的 backgroundColor 的值传递给子组件 CardSubTitle 并根据父 backgroundColor 更改文本颜色。 React-native 和 babel 对我来说是新的并且从未使用过状态。我尝试使用 {...props} 但没有成功。
卡片.js
const Card = (props) => {
return (
<TouchableItem onPress={() => {}} useOpacity>
<View style={[styles(props).card]}>{props.children}</View>
</TouchableItem>
);
};
Card.propTypes = {
onPress: T.func,
title: T.string,
color: T.string,
};
export default Card;
CardText.js
const Card = (props) => {
return (
<TouchableItem onPress={() => {}} useOpacity>
<View style={[styles(props).card]}>{props.children}</View>
</TouchableItem>
);
};
Card.propTypes = {
onPress: T.func,
title: T.string,
color: T.string,
};
export default Card;
【问题讨论】:
-
我可以帮你,你能用 React hooks 吗?
标签: react-native