Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode

前端 未结 6 1028
一个人的身影
一个人的身影 2020-12-17 08:44

I am trying to use a function as a prop inside a component and this component is a child of another component. But the function is not working.? Can I know why. This is the

6条回答
  •  青春惊慌失措
    2020-12-17 09:04

    The simplest solution to this type of scenario is to wrap your component with a DOM element that you can actually attach a ref to it. For example:

    import React, { createRef, Component } from "react";
    import ChildComponent from "./child-component";
    
    class MyComponent extends Component {
    
     componentDidMount() {
      const node = this.wrapper.current;
      /* Uses DOM node  */ 
    }
    
    wrapper = createRef();
    
    render () {
    return (
      
    {this.props.children}
    ); } } export default MyComponent;`

提交回复
热议问题