I try to implement a modal from materializecss into my react app:
const ModalCardMetrics = (props) => {
let modalInstance;
let modalBox = useRef();
useEffect(()=>{
modalInstance = window.M.Modal.init(modalBox.current, {})[0];
},[])
const openModal = ()=>{
modalInstance.open(); // modalInstance is undefined?!
}
return (
<div>
<div rel={modalBox}>...modalbox...</div>
<button onClick={openModal}>Menu</button>
</div>
)
}
Uncaught TypeError: modalInstance is undefined toggleModal ModalCardMetrics.js:90 React 14
In this codesandbox you see that my approach would work - I assume: I am using a cdn (in index.html) to load Materializecss and in the codesandbox it is done with the npm package and import. https://codesandbox.io/s/quiet-platform-ph8g6