I am trying to code a react component for a modal and getting the error: "Uncaught TypeError: this.setState is not a function" when the openModal() is called. Below is my code:
class Header {
constructor() {
this.state = { showModal: false };
}
openModal() {
this.setState({showModal: true});
}
closeModal() {
this.setState({showModal: false});
}
render() {
return (
<div className="Header">
<ModalDialog heading="heading" show={this.state.showModal}>
<p>Body</p>
</ModalDialog>
<div className="Header-container">
<Navigation className="Header-nav" />
<div className="Navigation2">
<Button bsStyle='primary' onClick={this.openModal.bind(this)}>Sign in</Button>
<Button bsStyle='info' href="/register" onClick={Link.handleClick}>Sign up</Button>
</div>
</div>
</div>
);
}
}
class ModalDialog {
render() {
if (this.props.show) {
return (
<div className="Overlay">
<Modal heading={this.props.heading}>
<div>{this.props.children}</div>
</Modal>
</div>
);
}
return null;
}
};
class Modal {
render() {
return (
<div className="Modal effect">
<h3>{this.props.heading}</h3>
<div className="content">
{this.props.children}
</div>
</div>
);
}
};
I am also trying to pass in a className into the element <div className="Modal effect">
from the Header component to change the dimensions of the Modal, is this possible?
Would be great if somebody could help me out with this. I am just starting out with React. Thanks