React: componentes y children

In this example below you will see how to do a React: componentes y children with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by adalab, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright adalab ©
  • HTML
  • CSS
  • JavaScript
    <div id="react-root"></div>

/*Downloaded from https://www.codeseek.co/adalab/react-componentes-y-children-WdZEQv */
    #react-root {
  display: flex;
  height: 100vh;
  width: 100vw;

  align-items: center;
  justify-content: center;
  
  background-color: rgba(0, 0, 0, 0.25);
}

.horizontal-center {
  text-align: center;
}


/*Downloaded from https://www.codeseek.co/adalab/react-componentes-y-children-WdZEQv */
    class Popup extends React.Component {
  render() {
    return (
      <div className={ `alert alert-${this.props.styling}` } role="alert">
        { this.props.children }
      </div>
    );
  }
}
// this.props.styling value from Bootstrap classes: primary, secondary, success, info, warning, danger, link


ReactDOM.render(
  <Popup styling="info">
    <h1 className="horizontal-center">Welcome</h1>
    <p>
      Thank you for visiting our webpage!
    </p>
    <p>
      We hope you enjoy our new shiny site!
    </p>
  </Popup>,
  document.getElementById('react-root')
);

Comments