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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <div id="feed">
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Karma|Nanum+Gothic:500')

$serif: 'Karma', 'Georgia', serif
$sans: 'Nanum Gothic', 'Verdana', sans-serif

@keyframes fadeIn 
  from 
    opacity: 0
    
  to
    opacity: 1
	
.fade-in
  animation: fadeIn .5s ease-in

body 
  background-color: #1d1f20

.container 
  margin: 0 auto
  max-width: 1200px

h1, h2, h3
  color: #fff
  margin: .5em 0
  font-family: $serif
  
h1 
  font-size: 2.5em
  
h2
  font-size: 1.5em
  line-height: 1.25
  
.tiles
  display: flex
  justify-content: space-between
  flex-wrap: wrap
  margin-top: 2em
  
  .tile 
    width: calc(50% - 3em)
    background-color: #f5f5f5
    padding: 1em
    display: flex
    flex-direction: column
    position: relative
    min-width: 300px
    margin: 1em auto
    
    .count 
      position: absolute
      font-size: .75em
      font-family: $sans
      top: 0
      right: 0
      background-color: #c34d41
      color: #fff
      padding: .5em .75em
      box-shadow: 0 0 3px #222
    
    h2
      color: #222
      margin: 0 2em 0 0
      font-weight: 600
      
    p
      font-family: $sans
      font-size: .9em
    
.load-more
  display: block
  border: 0
  margin: 1em auto
  padding: .75em 1em
  font-size: 1em
  background-color: #c34d41
  color: #fff
  font-weight: 500
  text-transform: uppercase
  font-family: $sans
  cursor: pointer
  
  &:focus
    outline: 1px solid rgba(255, 255, 255, .5)
  
  
  
  
              
            
!

JS

              
                class Feed extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      items: [],
      visible: 2,
      error: false
    };

    this.loadMore = this.loadMore.bind(this);
  }

  loadMore() {
    this.setState((prev) => {
      return {visible: prev.visible + 4};
    });
  }

  componentDidMount() {
    fetch("https://jsonplaceholder.typicode.com/posts").then(
      res => res.json()
    ).then(res => {
      this.setState({
        items: res
      });
    }).catch(error => {
      console.error(error);
      this.setState({
        error: true
      });
    });
  }

  render() {
    return (
      <section className="feed">
        <h1>Simple Load More/Pagination with React</h1>
        <h2>With Array.prototype.slice() and the power of component state!</h2>

        <div className="tiles" aria-live="polite">
          {this.state.items.slice(0, this.state.visible).map((item, index) => {
              return (
                <div className="tile fade-in" key={item.id}>
                  <span className="count">{index+1}</span>
                  <h2>{item.title}</h2>
                  <p>{item.body}</p>
                </div>
              );
            })}
          </div>
          {this.state.visible < this.state.items.length &&
             <button onClick={this.loadMore} type="button" className="load-more">Load more</button>
          }
        </section>
    );
  }
}

ReactDOM.render(<Feed />, document.getElementById('feed'));
              
            
!
999px

Console