npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-compose-layout

v0.4.0

Published

A React library for managing page layouts in a composable and efficient way. This library helps you create reusable layouts that persist across route changes, preventing unnecessary remounts of layout components.

Readme

react-compose-layout

A React library for managing page layouts in a composable and efficient way. This library helps you create reusable layouts that persist across route changes, preventing unnecessary remounts of layout components.

Features

  • 🔄 Persistent layouts across route changes
  • 🎯 Efficient layout management with minimal re-renders
  • 🔌 Optional integration with React Router
  • 📦 Lightweight with minimal dependencies (only requires React)

Installation

npm install react-compose-layout
# or
yarn add react-compose-layout

Requirements

  • React ^18.3.1
  • Node.js >=20.0.0

The library has been tested against React Router v6 but does not directly depend on it. React Router is an optional peer dependency that you can install if you need routing capabilities.

Usage

1. Wrap your app with PageLayoutProvider

First, wrap your application with the PageLayoutProvider:

import { PageLayoutProvider } from "react-compose-layout";

function App() {
  return <PageLayoutProvider>{/* Your app content */}</PageLayoutProvider>;
}

2. Create a Layout Component

Create your layout component as you normally would:

function MainLayout({ children, title }) {
  return (
    <div>
      <header>
        <nav>{/* Your navigation */}</nav>
      </header>
      <main>
        <h1>{title}</h1>
        {children}
      </main>
      <footer>{/* Your footer */}</footer>
    </div>
  );
}

3. Create a Page Layout

Use createPageLayout to create a layout component that can be used across different pages:

import { createPageLayout } from "react-compose-layout";

const Layout = createPageLayout({ Component: MainLayout });

4. Use the Layout in Your Pages

Apply the layout to your pages and pass any props it needs:

function HomePage() {
  return (
    <Layout title="Welcome to the Home Page">
      <p>This is our homepage content</p>
      {/* Your page content */}
    </Layout>
  );
}

function AboutPage() {
  return (
    <Layout title="About Us">
      <p>Learn more about our company</p>
      {/* Your page content */}
    </Layout>
  );
}

Example with React Router (Recommended)

For proper integration with React Router, you'll need to use the PageRenderOutlet component along with React Router's Outlet. Note that PageRenderOutlet can also be used without React Router in other scenarios where you need to control layout rendering:

import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";
import { PageLayoutProvider, PageRenderOutlet } from "react-compose-layout";

function App() {
  return (
    <BrowserRouter>
      <PageLayoutProvider>
        <Routes>
          <Route
            element={
              <PageRenderOutlet>
                <Outlet />
              </PageRenderOutlet>
            }
          >
            <Route path="/" element={<HomePage />} />
            <Route path="/about" element={<AboutPage />} />
          </Route>
        </Routes>
      </PageLayoutProvider>
    </BrowserRouter>
  );
}

How It Works

The library uses React's Context API to manage layouts efficiently. When you switch between pages that use the same layout, the layout component doesn't remount, improving performance and maintaining layout state. This is achieved through the PageLayoutProvider and PageRenderOutlet components working together to manage the layout lifecycle.

API Reference

PageLayoutProvider

A provider component that manages the layout state.

<PageLayoutProvider>{/* Your app content */}</PageLayoutProvider>

createPageLayout

A function that creates a layout component.

createPageLayout({ Component: LayoutComponent });

Parameters:

  • Component: The React component to be used as a layout

Returns:

  • A layout component that can be used to wrap page content

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.