Нужно обработать клик по элементу. Но результат всегда (TypeError: Cannot read property 'addEventListener' of null).
Я так понимаю он обрабатывается до того как произошла загрузка нужного компонента.
Помогите пожалуйста решить данную проблему.
код:
import './CSS/footer.css'
export function SignUp(props) {
return(
<div id = "signup" className ="ferSignUp">
<h3>Sign up <img src="img\icon-signup.png" alt="signup"></img></h3>
</div>
);
}
import React, { useEffect, useRef, useState } from "react";
import {SignUp, Basket} from './FooterElements'
import './CSS/footer.css'
export default class Footer extends React.Component{
constructor(props){
super(props);
this.state = {
}
}
render(){
return(
<div className = "fer">
<h1>3DStore</h1>
<div className = "ferElements">
<SignUp />
<Basket />
</div>
</div>,
<UseEffects/>
);
}
}
function UseEffects() {
const [ons, double] = useState("none");
const ref = useRef(ons);
useEffect(()=>{
const oneElem = document.getElementById("signup");
const twoElem = document.getElementById("signModall");
ref.current = ons;
oneElem.addEventListener("click", ()=> {
twoElem.style.display = double("block");
})
}, [ons]);
return UseEffects;
}