# react-stacked-pages-hook

> Manage a stack of pages in Gatsby

Latest version **0.4.8** (published 2021-07-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-stacked-pages-hook
pnpm add react-stacked-pages-hook
yarn add react-stacked-pages-hook
bun add react-stacked-pages-hook
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.8 |
| Published | 2021-07-07 |
| First published | 2020-05-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 24.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 689 |
| Author | Mathieu Dutour |
| Maintainers | mathieudutour |
| Keywords | react, hook, stacked notes |

## Links

- npm: https://www.npmjs.com/package/react-stacked-pages-hook
- Repository: https://github.com/mathieudutour/gatsby-digital-garden
- Homepage: https://github.com/mathieudutour/gatsby-digital-garden#readme
- Issues: https://github.com/mathieudutour/gatsby-digital-garden/issues
- npm.io page: https://npm.io/package/react-stacked-pages-hook

## Dependencies (2)

- [lodash.isequal](https://npm.io/package/lodash.isequal.md) ^4.5.0
- [lodash.throttle](https://npm.io/package/lodash.throttle.md) ^4.1.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.4.8 (latest) — 2021-07-07
- 0.4.6 — 2020-08-09
- 0.4.5 — 2020-07-20
- 0.4.4 — 2020-07-02
- 0.4.3 — 2020-07-02
- 0.4.2 — 2020-06-26
- 0.4.1 — 2020-06-26
- 0.4.0 — 2020-06-18
- 0.3.2 — 2020-05-26
- 0.3.1 — 2020-05-26
- 0.3.0 — 2020-05-25
- 0.2.0 — 2020-05-21
- 0.1.0 — 2020-05-20

## README

# react-stacked-pages-hook

Manage a stack of pages in Gatsby. It allows you to display multiple Gatsby page on the same one at runtime.

## Installation

```bash
npm install react-stacked-pages-hook
```

## Usage

In your layout component:

```js
import React, { useEffect, useRef, useCallback } from "react";
import Page from "../components/Page";
import {
  useStackedPagesProvider,
  LinkToStacked,
  useStackedPage,
  PageIndexProvider,
  StackedPagesProvider,
} from "react-stacked-pages-hook";

const PageContainer = ({ children, slug }) => {
  const [, { overlay, obstructed, highlighted }, i] = useStackedPage();

  return (
    <div
      className={`page-container ${overlay ? "page-container-overlay" : ""} ${
        obstructed ? "page-container-obstructed" : ""
      }  ${highlighted ? "page-container-highlighted" : ""}`}
      style={{ left: 40 * i, right: -585 }}
    >
      <div className="page-content">{children}</div>
      <LinkToStacked to={slug} className="obstructed-label">
        {slug}
      </LinkToStacked>
    </div>
  );
};

// A wrapper component to render the content of a page when stacked
const StackedPageWrapper = ({ children, slug, i }) => (
  <PageIndexProvider value={i}>
    <PageContainer slug={slug}>{children}</PageContainer>
  </PageIndexProvider>
);

const StackedLayout = ({ data, location, slug }) => {
  // Use this callback to update what you want to stack.
  // `pageQuery` will be similar to the data prop you get in a Page component.
  // You can return `null` to filter out the page
  const processPageQuery = useCallback((pageQuery) => pageQuery, []);

  const [state, scrollContainer] = useStackedNotesProvider({
    firstPage: { data, slug },
    location,
    processPageQuery,
    pageWidth: 625,
  });

  return (
    <div className="layout">
      <div className="page-columns-scrolling-container" ref={scrollContainer}>
        <div
          className="page-columns-container"
          style={{ width: 625 * (state.stackedPages.length + 1) }}
        >
          <StackedPagesProvider value={state}>
            {/* Render the stacked pages */}
            {state.stackedPages.map((page, i) => (
              <StackedPageWrapper i={i} key={page.slug} slug={page.slug}>
                <Page {...page} />
              </StackedPageWrapper>
            ))}
          </StackedPagesProvider>
        </div>
      </div>
    </div>
  );
};

export default StackedLayout;
```

Somewhere in your stacked page, you can use

```js
import {
  useStackedPages,
  useStackedPage,
  LinkToStacked,
} from "react-stacked-pages-hook";

const Component = () => {
  const [
    stackedPages,
    stackedPageStates,
    hookedNavigateToStackedPage,
    highlightStackedPage,
  ] = useStackedPages();

  const [
    currentPage,
    currentPageState,
    pageIndex,
    navigateToStackedPage,
    highlightStackedPage,
  ] = useStackedPage();

  return null;
};

const AnotherComponent = () => {
  return (
    <LinkToStacked to={"/stacked-page"}>
      Magic link that will stack a page
    </LinkToStacked>
  );
};
```

---
_Source: https://npm.io/package/react-stacked-pages-hook · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
