我是新来的反应者,我在尝试创建的应用程序中遇到问题。我有三个组成部分。因此,在主要组件中,我获取数据并将数据发送到进度条组件,当进度条加载时,我想访问另一个组件的功能。如何访问其他组件的功能?
主要组件
{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');
};