How to get refs from another component in React JS

前端 未结 4 580
时光取名叫无心
时光取名叫无心 2021-02-12 15:44

The code in main App component is as follows :

class App extends Component {
  componentDidMount(){
      console.log(this.ref);
      debugger;
  }

  render()         


        
4条回答
  •  滥情空心
    2021-02-12 15:58

    If your component are related (parent and child ) you can assign ref to child and can use it in parent

    If not then getElementById will come to rescue, but while selecting it please assign html type ex.

    const info = (document.getElementById("info") as HTMLDivElement)
    

提交回复
热议问题