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 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.

Quick-add: + add another resource

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.

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