I am new to ReactJS & learning to create model using Materialize css. https://materializecss.com
import React, { Component } from 'react';
import Modal from 'components/modal.jsx';
class Card extends Component {
constructor(props) {
super(props);
this.state = {
modal: false,
}
}
modalToggle = () => {
this.setState({modal: !this.state.modal})
console.log(this.state.modal);
}
render() {
return (
<div className="row">
<div className="col s12 m6" onClick={this.modalToggle}>
<div className="card blue-grey darken-1">
<div className="card-content white-text">
<span className="card-title">
Card Title
</span>
<p>
Hello I'm new card.
</p>
</div>
<div className="card-action">
<a href="#">Click Me</a>
<a href="#">Don't Click Me</a>
</div>
</div>
</div>
<Modal onClick={this.modalToggle} status={this.state.modal} />
</div>
);
}
}
ReactDom.render(<App />, document.getElementById('root'));
And my Modal Component looks like,
import React, { Component } from 'react';
class Modal extends Component {
render() {
return(
<div id="modal1" className="modal modal-fixed-footer">
<div className="modal-content">
<h4>Modal Title</h4>
<p>Description</p>
</div>
<div className="modal-footer">
<a href="#!" className="modal-close waves-effect waves-green btn-flat">
Click Me
</a>
</div>
</div>
);
}
}
export default Modal;
When the card get clicked I want my modal show up. For that I have created function modalToggle. Can someone please guide me how to make the modal pop up. The code is running perfectly and also printing the state of modal. Is there anything wrong with my code.
I know that one solution to this is React-Materialize. I want to pop modal without React-materialize ... Is there any solution without using the React-Materliaze.
I would appreciate the help.