从类到功能组件的引用

问题描述

我使用父类中的 ref 来访问子类。

但是在这种情况下,我想从父类访问子功能组件。

在父类中。

class Waveform extends Component {

  constructor(props){
    super(props);
    this.track_0Ref = React.createRef();
  }
  handlePlay = () => {
    console.log("play button click");
    var node = this.track_0Ref.current
    console.log(node); //  show null......
  }
  render() {
    return (
      <AudioTrack trackNum="0" ref={this.track_0Ref}/>
    )
  }
}

在子功能组件中。

const AudioTrack = (props) => {
  useEffect(() => {});
  return(  
    <GridContainer>
    <PlayButton onClick={this.handlePlay} />
    <div id=track0 ></div>
    </GridContainer>
  );
}

父类中似乎没有对象this.track_0Ref.current...

我应该哪里错了??

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)