javascript - 不确定如何通过单击 react-native 中的按钮来呈现此组件
问题描述
以下是一个barChart
函数。barChart
它在屏幕上返回一个-
const barCharts = () => {
const fill = 'rgb(134, 65, 244)'
const data = [50, 10, 40, 95, -4, -24, null, 85, undefined, 0, 35, 53, -53, 24, 50, -20, -80]
return (
<View style={styles.sectionContainer}>
<BarChart style={{ height: 200 }} data={data} svg={{ fill }} contentInset={{ top: 30, bottom: 30 }}>
<Grid />
</BarChart>
</View>
);
};
我希望这个barChart
组件在单击按钮时呈现。我当前的环境是 react-native ios。单击 App.js 中的按钮后,我将如何完成渲染?
解决方案
您可以为此使用道具或状态。
const barCharts = () => {
const { showBarChart } = this.props;
const fill = 'rgb(134, 65, 244)'
const data = [
50, 10, 40, 95, -4, -24, null, 85, undefined, 0, 35, 53, -53, 24, 50,
-20, -80
];
return (
<View style={styles.sectionContainer}>
{showBarChart && (
<BarChart
style={{ height: 200 }}
data={data}
svg={{ fill }}
contentInset={{ top: 30, bottom: 30 }}
>
<Grid />
</BarChart>
)}
</View>
);
};
推荐阅读
- php - 如果会话值未使用 PHP 设置,则从数据库中检索会话内容
- javascript - 在jQuery中下载带有换行符的Textarea内容
- php - 记录十进制无空格超过 999
- django - 如何将待处理任务的数量添加到 List Json
- pandas - 熊猫,很高兴将列表作为元素,或者只是将其展平?
- elasticsearch - Elasticsearch: TransportError(406, u'Content-Type header is missing')
- java - Jenkins 使用参数和 SVN 构建作业
- php - setFetchMode 被忽略
- mongodb - MongoDB bson.M 查询
- java - Hystrix Fallback 未在单元测试中执行