Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://fb.me/react-15.1.0.js"></script>
  <script src="https://fb.me/react-dom-15.1.0.js"></script>
</head>
<body>
  <button class="show">show</button>
  <button class="hide">hide</button>
  <div id="root"></div>
</body>
</html>
 
class Modal extends React.Component {
  state = {};
  show = data => {
    let nextState;
    if (data === false) {
      nextState = {show: false};
    } else {
      nextState = {show: true};
      if (data) {
        nextState.data = data;
      }
    }
    this.setState(nextState);
  }
  render() {
    return <dialog open={this.state.show}>
      <h3>Modal</h3>
      <p>{this.state.data}</p>
    </dialog>;
  }
}
document.addEventListener('DOMContentLoaded', () => {
  const modal = ReactDOM.render(<Modal title='1'/>, document.querySelector('#root'));
  document.querySelector('.show').addEventListener('click', () => {
    modal.show(Math.random());
  });
  document.querySelector('.hide').addEventListener('click', () => {
    modal.show(false);
  });  
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
aves84pro
0viewers