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 id="app"></div>
              
            
!

CSS

              
                body {
  height: 100vh;
  background: black url('http://dodskypict.com/D/Star-Wars-Wallpaper-On-Wallpaper-Hd-4-1920x1080.jpg')no-repeat center center;
  background-size: cover;
}
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  color: yellow;
}

.tg {
  border-collapse: collapse;
  border-spacing: 0;
  width: 90%;
  margin: 10px auto;
}
.tg td {
  font-family: Arial, sans-serif;
  font-size: 14px;
  padding: 10px 5px;
  border-style: solid;
  border-color: yellow;
  border-width: 3px;
  overflow: hidden;
  word-break: normal;
  color: white;
  font-weight: bold;
  background: black;
  &:hover {
    background: yellow;
    color: black;
  }
}
.tg th {
  font-family: Arial, sans-serif;
  font-size: 14px;
  font-weight: normal;
  padding: 10px 5px;
  border-style: solid;
  border-width: 3px;
  border-color: yellow;
  overflow: hidden;
  word-break: normal;
  font-weight: bold;
  color: white;
}
.tg .tg-yw4l {
  vertical-align: top;
}

#pagination {
  margin-top: auto;
  padding: 10px;
  display: flex;
  justify-content: center;
  button {
    margin: 0 5px;
    padding: 5px 10px;
    background: none;
    border: solid 2px yellow;
    color: yellow;
    font-weight: bold;
    cursor: pointer;
    &:hover {
      background: yellow;
      color: black;
    }
  }
}

              
            
!

JS

              
                // const LoaderHOC = (Component) => {
//   return class LoaderHOC extends React.Component {
//     render() {
//       return this.props.characters.length === 0 ? 
//         <div style={{color: 'yellow'}}>Loading...</div> : 
//         <Component {...props} />
//     }
//   }
// }

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      characters: [],
    }
  }
  
  fetchData = (link) => {
    fetch(link)
    .then(resp => resp.json())
    .then(data => {
      this.setState({
        characters: data.results,
        prev: data.previous,
        next: data.next,
      })
      console.log(data)
    })
  }
  
  componentDidMount(){
    this.fetchData('https://swapi.co/api/people/?page=1')     
  }
  
  moreResults = (link) => {
    this.fetchData(`${link}`)
  }
    
  render() {
    const { characters, next, prev } = this.state;
    return(
      <div id="app">
        <Characters characters={characters} />
    
        <div id="pagination">
          {prev && <button onClick={() => this.moreResults(prev)}>Prev</button>}
          {next && <button onClick={() => this.moreResults(next)}>Next</button>}
        </div>    
      </div>
    )
  }
}

const Characters = ({ characters }) => (
  <table className="tg">
    <tr>
      <th class="tg-031e">Name</th>
      <th class="tg-yw4l">Height</th>
      <th class="tg-yw4l">Mass</th>
    </tr>
      { 
        characters.length === 0 ? 
          <div>Loading...</div> : 
        characters.map(character => <CharacterInfo character={character}/>) 
      }
  </table>
)

const CharacterInfo = ({ character: { name, height, mass } }) => (
  <tr>
    <td class="tg-yw4l">{name}</td>
    <td class="tg-yw4l">{height}</td>
    <td class="tg-yw4l">{mass}</td>
  </tr>
)


Characters.propTypes = {
  characters: PropTypes.array.isRequired
}

CharacterInfo.propTypes = {
  name: PropTypes.string.isRequired,
  height: PropTypes.number.isRequired
}

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

Console