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-permify

v0.1.1

Published

A clean, reusable React package for permission and role-based access control.

Readme

🛡️ react-permify

A powerful, light-weight, and type-safe React package for Permission and Role-Based Access Control (RBAC).

npm version License: MIT


🔥 Features

  • ⚛️ Pure React: Built with standard Hooks and Context.
  • 🛡️ Type-Safe: First-class TypeScript support.
  • 🧩 Flexible Components: Conditional rendering with <Can />.
  • 🪝 Custom Hooks: Access permissions anywhere with usePermission().
  • 🏗️ HOC Support: Protect components with withPermission().
  • 🗺️ Permission Mapping: Map roles to permissions automatically.
  • 🔄 Dynamic Updates: Update user roles/permissions on the fly.
  • 💾 Persistence: Built-in support for localStorage persistence.
  • 📦 Zero-Dependencies: Extremely small bundle size.

🚀 Installation

npm install react-permify
# or
yarn add react-permify

🛠️ Quick Start

1. Wrap your App

import { PermissionProvider } from 'react-permify';

const user = { 
  id: 1, 
  role: 'admin',
  permissions: ['DELETE_USER'] 
};

// Optional: Map roles to permissions automatically
const permissionMap = {
  admin: ['EDIT_POST', 'DELETE_POST'],
  editor: ['EDIT_POST'],
  viewer: ['VIEW_POST']
};

function App() {
  return (
    <PermissionProvider 
      user={user} 
      permissionMap={permissionMap}
      persistKey="my-app-auth" // Optional: persistence
    >
      <Dashboard />
    </PermissionProvider>
  );
}

2. Guard Components with <Can />

import { Can } from 'react-permify';

// Check by Role
<Can role="admin">
  <DeleteButton />
</Can>

// Check by Permission
<Can permission="EDIT_POST">
  <EditButton />
</Can>

// With Fallback
<Can 
  role={['admin', 'manager']} 
  fallback={<p>Access Denied</p>}
>
  <AdminPanel />
</Can>

// Require All
<Can 
  permission={['READ', 'WRITE']} 
  requireAll={true}
>
  <SecretEditor />
</Can>

3. Use the usePermission Hook

import { usePermission } from 'react-permify';

const MyComponent = () => {
  const { hasRole, hasPermission, user, updatePermissionState } = usePermission();

  const handleLogin = (userData) => {
    // Update state dynamically after login
    updatePermissionState({
      user: userData,
      roles: userData.roles,
    });
  };

  if (hasPermission('DELETE_USER')) {
    return <button>Delete User</button>;
  }

  return <div>Welcome, {user?.name}</div>;
};

4. High-Order Component (HOC)

import { withPermission } from 'react-permify';

const SensitiveComponent = () => <div>Top Secret</div>;

export default withPermission(SensitiveComponent, {
  role: 'admin',
  fallback: <Redirect to="/unauthorized" />
});

📖 API Reference

<PermissionProvider />

| Prop | Type | Description | | :--- | :--- | :--- | | user | User | Initial user object. | | roles | string[] | Global roles for the session. | | permissions | string[] | Global permissions for the session. | | permissionMap | Record<string, string[]> | Mapping of roles to permissions. | | isLoading | boolean | Set to true while fetching data. | | loadingComponent| ReactNode | Component to show while isLoading is true. | | persistKey | string | localStorage key for persistence. |

<Can />

| Prop | Type | Description | | :--- | :--- | :--- | | role | string \| string[] | Role(s) required to view children. | | permission | string \| string[] | Permission(s) required to view children. | | requireAll | boolean | If true, all roles/perms must match. (default: false) | | fallback | ReactNode | Rendered if access is denied. |


📜 License

MIT © react-permify