React: How to access refs in this.props.children

后端 未结 2 1975
感动是毒
感动是毒 2021-02-08 23:55

I want to call a function of a child component.
Is there a possibility to get refs from this.props.children in React.

var ComponentSection = React.createClas         


        
2条回答
  •  一生所求
    2021-02-09 00:27

    You are trying to set a ref on a

    instead of a React component.

    You could also refactor your code so that only needs to know about the component, and render it in it's render function.

    var ComponentSection = React.createClass({
      componentDidMount: function() {
        this.refs.inner.resize();
      },
    
      render: function() {
        return ( 
            
    ); } }); var MainComponent = React.createClass({ render: function() { return ( ); } });

    Here is a working JSFiddlle.

提交回复
热议问题