我将颜色作为 props.color 导入到我的功能组件中,并将其设置为状态“tagColor”。当我在样式表中使用 tagColor 作为值来设置背景颜色时,我收到错误“找不到变量 tagColor”
如何在样式表中使用变量?
const Tag = (props) => {
const [tagColor, setColor] = useState(props.color)
return (
<View style={styles.container}>
<TouchableOpacity style={styles.tag} title='tag'>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
container: {
alignItems: "center",
justifyContent: "center",
height: 25,
display: 'flex'
},
tag: {
backgroundColor: tagColor,
}
});
export default Tag;
Run Code Online (Sandbox Code Playgroud)