Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <div id="react-root" class="flex-center"></div>
            
          
!

CSS

            
              #react-root {
  height: 100vh;
  width: 100vw;
}

.flex-center {
  display: flex;

  align-items: center;
  justify-content: center;
}

.section-murrays_list {
  display: flex;
  
  flex-direction: columns;
  flex-wrap: wrap;
}
.section-murrays_list > li {
  list-style: none;
}
            
          
!

JS

            
              class Loader extends React.Component {
  render(){
    return (<p>Loading...</p>);
  }
}


/* components/MurrayList.js */
//import React from 'react';
//import RandomMurray from `./RandomMurray`;
//import ReloadButton from './ReloadButton';

class MurrayList extends React.Component {
  constructor(props) {
    super(props);
    
    // nos aseguramos de que este callback se ejecute siempre sobre el componente enlazándolo a la instancia con "bind"
    this.handleClick = this.handleClick.bind(this);
    
    this.state = {
      loading: true
    };
    
    setTimeout(() => this.setState({loading: false}), 2000);
  }
  
  
  
  handleClick() {
    this.setState({loading: true})
    setTimeout(() => this.setState({loading: false}), 2000);
     // se ejecutará el método `render()` de MurrayList, que hará a su vez que se ejecute de nuevo el método `render()` de los hijos
  }
  
  render() {
    const { handleClick } = this;
    
    return (
      <section className="section-murrays">
        <h1>All <del>Cats</del> Murrays Are Beautiful</h1>
        {this.state.loading? <Loader /> :
        (<ul className="section-murrays_list">
          <li><RandomMurray /></li>
          <li><RandomMurray /></li>
          <li><RandomMurray /></li>
        </ul>)}
        {/* pasamos handleClickAndReload al hijo como prop */}
        <ReloadButton actionToPerform={ handleClick } label="More murrays"/>
      </section>
    );
  }
}

//export default MurrayList;

/* components/ReloadButton.js */
//import React from 'react';

class ReloadButton extends React.Component {
  render() {
    const {
      label = "More",
      actionToPerform
    } = this.props;
 
    return (
      // Registramos el escuchador que recibimos por props. ¡Lifting hecho!
      <button onClick={ actionToPerform }>{ label }</button>
    );
  }
}

//export default ReloadButton;

/* components/RandomMurray.js */
//import React from 'react';

const getRandomInteger = (max, min) => Math.floor(Math.random() * (max - min + 1)) + min;
const MIN_SIZE = 200;
const MAX_SIZE = 400;

class RandomMurray extends React.Component {
  render() {
    const randomMurray = getRandomInteger(MIN_SIZE, MAX_SIZE);

    return (
      <img src={ `http://www.fillmurray.com/200/${randomMurray}` } alt="Random murray" />
    );
  }
}

//export default RandomMurray;

/* index.js */
//import React from 'react';
//import ReactDOM from 'react-dom';
//import './stylesheets/index.css';
//import MurrayList from './components/MurrayList';

ReactDOM.render(
  <MurrayList />,
  document.getElementById('react-root')
);
            
          
!
999px

Console