javascript - reactjs中如何访问另一个组件的功能?
问题描述
我是新手,我在尝试创建的应用程序中遇到问题。我有三个组件。因此,在主组件中,我获取数据并将数据发送到进度条组件,当进度条加载时,我想访问另一个组件的功能。如何访问其他组件的功能?
主要部件
{analysis.tontop.map(({ tone, value }) => (
<MyProgressBar
onClick={() => this.handleSentClick(tone)} //this is where I want to call the function of the sound component. or is this not the correct place to call the function of the other component?
value={value}
text={tone}
key={tone}
/>
))}
进度条组件
const MyProgressBar = ({ value, text, onClick }) => {
return (
<ProgressBar
onClick={onClick}
max={100}
now={value}
/>
</div>
);
};
我要从中访问功能的组件
function Sound(tone, enteredText) {
const handleSentClick = ({ tone, onClick }) => {
//this is the function that I want to access in the main component
console.log('something something');
};
解决方案
推荐阅读
- python - 为什么在我更改超时变量后,Amazon RDS 上的 MySQL 会不断使我的连接超时?
- postgresql - 与 postgresql 一起使用时出现 EF 核心迁移脚本错误
- php - 从 MySQL 数据库中获取表列表
- python - Python 中的大型 csv 文件
- c# - 如何访问 TemplateField asp.net 中的 gridview 值
- python - 如何检查前一行的值(OHLC 股票数据)?
- node.js - 从函数返回超级代理响应对象
- c - C 宏编译器警告
- amazon-ec2 - 节点(AWS EC2 实例)如何读取其 Kubernetes 标签?
- c - 当我使用 goto 标签再次运行代码而不退出输出时,文件在 c 语言中找不到