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="container"></div>

              
            
!

CSS

              
                @import "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css";

#container {
  margin: 1rem;
}

.repo-title {
  margin-bottom: 1.5rem;
}

.listing {
  margin-bottom: 1rem;
}
              
            
!

JS

              
                import ReactPaginate from "https://cdn.skypack.dev/react-paginate@7.1.3";
import React, {
  useEffect,
  useState
} from "https://cdn.skypack.dev/react@17.0.1";
import ReactDOM from "https://cdn.skypack.dev/react-dom@17.0.1";

// Util for GitHub API.

function getGitHubPageCount(response) {
  const REGEX_GITHUB_HEADER_LINK = /<\S*\&page=(\d)>; rel="last"/gm;
  // Extract pageCount from Link header.
  return Number(REGEX_GITHUB_HEADER_LINK.exec(response.headers.get("Link"))[1]);
}

// Actual React-Paginate example.
// https://github.com/AdeleD/react-paginate

function Repositories({ repositories, className }) {
  if (repositories.length === 0) {
    return (
      <div className="alert alert-warning" role="alert">
        No results.
      </div>
    );
  }
  // TODO Format with https://getbootstrap.com/docs/5.1/components/card/
  //   https://getbootstrap.com/docs/5.1/components/list-group/
  return (
    <div className={className}>
      {repositories.map((repository) => (
        <div className="repository-entry">
          <h4>{repository.name}</h4>
        </div>
      ))}
    </div>
  );
}

function PaginateDemoApp({ orgName, perPage }) {
  const [repositories, setRepositories] = useState([]);
  const [pageOffset, setPageOffset] = useState(0);
  const [pageCount, setPageCount] = useState(0);
  const [apiError, setApiError] = useState(null);

  useEffect(async () => {
    const response = await fetch(
      `https://api.github.com/orgs/${orgName}/repos?${new URLSearchParams({
        per_page: perPage,
        page: pageOffset
      })}`
    );
    const responseJson = await response.json();
    if (!response.ok) {
      setApiError(responseJson.message);
      setRepositories([]);
      setPageCount(0);
      return;
    }
    const newPageCount = getGitHubPageCount(response);
    console.log(responseJson, newPageCount);
    setRepositories(responseJson);
    setPageCount(newPageCount);
  }, [pageOffset, perPage]);

  const handlePageChange = (event) => {
    console.log(event);
    // TODO Only change displayed selected page
    // when its content is loaded in useEffect.
    setPageOffset(event.selected);
  };

  return (
    <div style={{ marginTop: "1rem" }}>
      <h3 className="repo-title">{orgName} GitHub repositories</h3>
      <ReactPaginate
        previousLabel="Previous"
        nextLabel="Next"
        pageClassName="page-item"
        pageLinkClassName="page-link"
        previousClassName="page-item"
        previousLinkClassName="page-link"
        nextClassName="page-item"
        nextLinkClassName="page-link"
        breakLabel="..."
        breakClassName="page-item"
        breakLinkClassName="page-link"
        pageCount={pageCount}
        marginPagesDisplayed={2}
        pageRangeDisplayed={5}
        onPageChange={handlePageChange}
        containerClassName="pagination"
        activeClassName="active"
        forcePage={pageOffset}
      />
      {apiError && (
        <div className="alert alert-danger" role="alert">
          {apiError}
        </div>
      )}
      <Repositories className="listing" repositories={repositories} />
      <ReactPaginate
        previousLabel="Previous"
        nextLabel="Next"
        pageClassName="page-item"
        pageLinkClassName="page-link"
        previousClassName="page-item"
        previousLinkClassName="page-link"
        nextClassName="page-item"
        nextLinkClassName="page-link"
        breakLabel="..."
        breakClassName="page-item"
        breakLinkClassName="page-link"
        pageCount={pageCount}
        marginPagesDisplayed={2}
        pageRangeDisplayed={5}
        onPageChange={handlePageChange}
        containerClassName="pagination"
        activeClassName="active"
        forcePage={pageOffset}
      />
    </div>
  );
}

ReactDOM.render(
  <PaginateDemoApp orgName="YtoTech" perPage={5} />,
  document.getElementById("container")
);

              
            
!
999px

Console