I have the form with different inputs (an example is down) when I click someone from them and if another input is open I want to close them.
Maybe someone can say where is my an error? Thanks!
My code look:
class SignUp extends Component {
constructor() {
super();
this.state = {
selectedCode: false,
};
}
componentDidMount() {
document.addEventListener("click", this.handleClickOutside);
}
componentWillUnmount() {
document.removeEventListener("click", this.handleClickOutside);
}
handleClickOutside(e) {
if (e.target.id !== "code") {
this.setState({
selectedCode: false // here is an error
});
} else {
console.log("YES CODE");
}
}
render (){
return (
<form >
<input .../>
<input id="code" .../>
</form>
}