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
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;`