cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <html>

<body>

  <div class="container-fluid" <aside>
    <h1>React Github Viewer Example</h1>
    <p>This is a React example that's just a tad less trivial than "hello world".  It is based on some code from <a href="https://www.youtube.com/watch?v=NpMnRifyGyw">this video</a>, but here instead of using jpms and systemjs, we set up the demo in CodePen.</p>
    <p>Listed below are some of the repositories in the <a href="https://github.com/codesolid">CodeSolid Github repository</a>.  We use the fetch polyfill to support non-chrome browsers, and use fetch to connect to the Github API.</p>
    </aside>
    <main id="app">
    </main>
  </div>
</body>

</html>
            
          
!
            
              // The entire API
var reposForUser = function(userName) {
  let url = `https://api.github.com/users/${userName}/repos`;
  return fetch(url).
  then(response => response.json());
};

// The frun end
class Repo extends React.Component {
  render() {
    let repo = this.props.repo;
    return (
      <div key={repo.id}>
        <h3>{repo.name}</h3>
        <p>{repo.description}</p>
      </div>);
  }
}

class RepositoryList extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      repos: []
    };
  }

  componentDidMount() {
    reposForUser('CodeSolid').then((repos) => {
      this.setState({
        repos: repos
      });
    });
  }

  // Show an individual repo using an ES6-class-based child component.
  // Shown below is another function that does it in a more terse
  // way.
  showRepo(repo) {
    return <Repo repo={repo} />;
  }

  // Another way to do it was this:
  // "The simplest way to define a component is to write a JavaScript function"...
  // https://facebook.github.io/react/docs/components-and-props.html
  // This code is uncalled, but works as a drop-in replacement for showRepo,
  // above.
  showRepoLegacy(repo, index) {
    return (
      <div key={index}>
        <h3>{repo.name}</h3>
        <p>{repo.description}</p>
      </div>);
  }

  render() {
    return (
      <div>{this.state.repos.map(this.showRepo)}</div>
    );
  }
}

ReactDOM.render(<RepositoryList />, document.getElementById("app"));
            
          
!
999px
Loading ..................

Console