I am trying to catch an element using an ID in React, but I could not.
render() {
//Looping through all menus
let menuOptions = this.props.menuLists.map(menuList => {
return (
<li className="nav-item active" key={menuList.name}>
<a className="nav-link" href={menuList.anchorLink}>
{menuList.name}
</a>
</li>
);
});
return (
<React.Fragment>
<div id="animSec">
<canvas id="myCanvas" />
</div>
</React.Fragment>
);
}
I want to call the myCanvas ID.
I tried by this.refs
, but it's sent me undefined. I also tried react-dom
:
ReactDOM.findDOMNode(this.refs.myCanvas);
but get nothing. I call findDOMNode
on the constructor first and I tried componentDidMount
but get nothing.