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-simple-layer

v1.0.0

Published

A simple way to create a react layer.

Readme

react-simple-layer

A simple way to create a react layer.

Install

npm install react-simple-layer

Quick Start

1. Register LayerRoot in your app

First, you need to add LayerRoot component to your application root:

import React from 'react';
import { LayerRoot } from 'react-simple-layer';

function App() {
  return (
    <div>
      {/* Your app content */}
      <YourComponents />
      
      {/* LayerRoot should be placed at the end */}
      <LayerRoot />
    </div>
  );
}

2. Create and use layers

import { createLayer, LC } from 'react-simple-layer';

// Define your layer component
const Modal: LC<{ title: string; content: string }> = ({ title, content, layer }) => {
  return (
    <div className="modal">
      <h1>{title}</h1>
      <p>{content}</p>
      <button onClick={layer.destroy}>Close</button>
    </div>
  );
};

// Create layer instance
const modalLayer = createLayer(Modal);

// Render the layer
modalLayer.render({
  title: 'Hello',
  content: 'This is a modal!'
});

// Destroy when needed
// modalLayer.destroy();

API Reference

LayerRoot

The root component that renders all layers. Must be placed in your app to enable layer functionality.

Props

  • root?: string - The ID of the DOM element to render layers into. Default: 'layer-root'

Example

// Use default root
<LayerRoot />

// Use custom root ID
<LayerRoot root="my-custom-root" />

createLayer

function createLayer<P>(Component: LC<P>, key?: string): LayerInstance<P>

Creates a layer instance from a component.

Parameters

  • Component: LC<P> - The layer component. It receives props of type P and a special layer prop.
  • key?: string - Optional unique key for the layer. If not provided, a random key will be generated.

Returns

Returns a LayerInstance<P> object with the following properties:

  • layer: Layer - The layer object containing:

    • key: string - Unique identifier for the layer
    • component: FC<P> - The wrapped component
    • destroy(): void - Method to destroy this layer
  • render(props?: Omit<P, 'layer'>): void - Renders the layer with the given props

  • destroy(): void - Removes the layer from the DOM

LC<P>

Type definition for layer components.

type LC<P> = FC<P & { layer: Layer }>

Your component receives:

  • All props of type P
  • A special layer prop with key, component, and destroy() method

Examples

Modal Dialog

import { createLayer, LC, LayerRoot } from 'react-simple-layer';

const Modal: LC<{ title: string; onConfirm: () => void }> = ({ 
  title, 
  onConfirm, 
  layer 
}) => {
  const handleConfirm = () => {
    onConfirm();
    layer.destroy();
  };

  return (
    <div className="modal-overlay">
      <div className="modal">
        <h2>{title}</h2>
        <button onClick={handleConfirm}>Confirm</button>
        <button onClick={layer.destroy}>Cancel</button>
      </div>
    </div>
  );
};

const modalLayer = createLayer(Modal);

// Use in your app
function MyApp() {
  const showModal = () => {
    modalLayer.render({
      title: 'Confirm Action',
      onConfirm: () => console.log('Confirmed!')
    });
  };

  return (
    <div>
      <button onClick={showModal}>Open Modal</button>
      <LayerRoot />
    </div>
  );
}

Toast Notification

const Toast: LC<{ message: string; type: 'success' | 'error' }> = ({ 
  message, 
  type, 
  layer 
}) => {
  React.useEffect(() => {
    const timer = setTimeout(() => {
      layer.destroy();
    }, 3000);
    return () => clearTimeout(timer);
  }, []);

  return (
    <div className={`toast toast-${type}`}>
      {message}
      <button onClick={layer.destroy}>×</button>
    </div>
  );
};

const toastLayer = createLayer(Toast);

// Show toast
toastLayer.render({
  message: 'Success!',
  type: 'success'
});

Drawer

const Drawer: LC<{ children: React.ReactNode }> = ({ children, layer }) => {
  return (
    <div className="drawer-overlay" onClick={layer.destroy}>
      <div className="drawer" onClick={(e) => e.stopPropagation()}>
        <button className="close-btn" onClick={layer.destroy}>×</button>
        {children}
      </div>
    </div>
  );
};

const drawerLayer = createLayer(Drawer);

drawerLayer.render({
  children: <div>Drawer content here</div>
});

TypeScript Support

Full TypeScript support with type inference:

interface MyLayerProps {
  title: string;
  count: number;
}

const MyLayer: LC<MyLayerProps> = ({ title, count, layer }) => {
  // title and count are typed
  // layer is automatically typed
  return <div>{title}: {count}</div>;
};

const myLayer = createLayer(MyLayer);

// Type-safe render
myLayer.render({ title: 'Hello', count: 42 }); // ✓
myLayer.render({ title: 'Hello' }); // ✗ Error: count is required