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

@geee-be/react-utils

v1.4.0

Published

A collection of powerful, type-safe React hooks and utility functions. Includes state management, SSR-compatible hooks, device detection, and browser API wrappers.

Readme

@geee-be/react-utils

A collection of powerful, type-safe React hooks and utility functions designed to enhance modern React applications. Built with TypeScript, SSR compatibility, and performance in mind.

npm version TypeScript License: MIT

✨ Features

  • 🪝 Custom React Hooks - Enhanced state management and utility hooks
  • 🔒 Type Safe - Full TypeScript support with comprehensive type definitions
  • 🌐 SSR Compatible - Works seamlessly with Next.js and other SSR frameworks
  • Performance Focused - Optimized for minimal re-renders and memory usage
  • 🧩 Modular - Tree-shakeable exports for optimal bundle size
  • 🔧 Browser API Wrappers - Safe abstractions for modern browser features
  • 📱 Device Detection - Responsive utilities for different environments
  • 🔄 State Persistence - Local storage integration with sync capabilities

📋 Installation

npm install @geee-be/react-utils
# or
pnpm add @geee-be/react-utils
# or
yarn add @geee-be/react-utils

Peer Dependencies

npm install react react-dom

Required versions:

  • React >= 18.0.0

🚀 Quick Start

import { useLocalState, useIsClient, useIsMobile } from '@geee-be/react-utils';

function MyComponent() {
  const [theme, setTheme] = useLocalState('theme', 'light');
  const isClient = useIsClient();
  const isMobile = useIsMobile();

  if (!isClient) {
    return <div>Loading...</div>;
  }

  return (
    <div className={`theme-${theme} ${isMobile ? 'mobile' : 'desktop'}`}>
      <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
        Toggle Theme
      </button>
    </div>
  );
}

🪝 Hooks Overview

State Management

useLocalState

Enhanced useState with localStorage persistence and cross-tab synchronization.

import { useLocalState } from '@geee-be/react-utils';

function Settings() {
  const [settings, setSettings] = useLocalState('user-settings', {
    theme: 'light',
    language: 'en'
  });

  return (
    <div>
      <button onClick={() => setSettings(prev => ({ ...prev, theme: 'dark' }))}>
        Enable Dark Mode
      </button>
    </div>
  );
}

Features:

  • Automatic localStorage synchronization
  • Cross-tab state updates
  • SSR-safe initialization
  • Type-safe with TypeScript inference

useHistoryState

State management with browser history integration for navigation state persistence.

import { useHistoryState } from '@geee-be/react-utils';

function SearchPage() {
  const [query, setQuery] = useHistoryState('search', '');

  return (
    <input
      value={query}
      onChange={(e) => setQuery(e.target.value)}
      placeholder="Search..."
    />
  );
}

Environment Detection

useIsClient

Detect client-side rendering vs server-side rendering to prevent hydration mismatches.

import { useIsClient } from '@geee-be/react-utils';

function ClientOnlyFeature() {
  const isClient = useIsClient();

  if (!isClient) {
    return <div>Loading...</div>; // Server-side fallback
  }

  return <ExpensiveClientComponent />;
}

useIsMobile

Responsive device detection with customizable breakpoints.

import { useIsMobile } from '@geee-be/react-utils';

function ResponsiveNav() {
  const isMobile = useIsMobile(768); // Custom breakpoint

  return isMobile ? <MobileNav /> : <DesktopNav />;
}

Communication

useBroadcastChannel

Cross-tab/window communication using the Broadcast Channel API with fallback.

import { useBroadcastChannel } from '@geee-be/react-utils';

function ChatApp() {
  const [message, postMessage] = useBroadcastChannel('chat-channel');

  useEffect(() => {
    if (message) {
      console.log('Received message:', message);
      // Handle incoming message from other tabs
    }
  }, [message]);

  const sendMessage = () => {
    postMessage({ text: 'Hello from another tab!', timestamp: Date.now() });
  };

  return <button onClick={sendMessage}>Send Message</button>;
}

🛠️ Utility Functions

Component Helpers

ClientOnly

Wrapper component for client-side only rendering.

import { ClientOnly } from '@geee-be/react-utils';

function App() {
  return (
    <div>
      <h1>Server and Client Rendered</h1>
      <ClientOnly>
        <ExpensiveClientComponent />
      </ClientOnly>
    </div>
  );
}

withSubComponents

Utility for creating compound components with sub-components.

import { withSubComponents } from '@geee-be/react-utils';

// Create compound components easily
const Card = withSubComponents(CardRoot, {
  Header: CardHeader,
  Content: CardContent,
  Footer: CardFooter
});

// Usage
<Card>
  <Card.Header>Title</Card.Header>
  <Card.Content>Content here</Card.Content>
</Card>

Monitor

Development component for monitoring component renders and lifecycle.

import { Monitor } from '@geee-be/react-utils';

function DebugComponent() {
  return (
    <Monitor label="MyComponent">
      <MyComponent />
    </Monitor>
  );
}
// Logs: "MyComponent mounted", "MyComponent rendered 1", etc.

Effects and Interactions

createRipple

Material Design ripple effect implementation for click interactions.

import { createRipple } from '@geee-be/react-utils';

function RippleButton() {
  return (
    <button
      onClick={createRipple}
      className="relative overflow-hidden"
    >
      Click for Ripple Effect
    </button>
  );
}

// Or use with custom event handler
function CustomButton() {
  const handleClick = (event) => {
    createRipple(event);
    // Your custom logic here
  };

  return (
    <button
      onClick={handleClick}
      className="relative overflow-hidden"
    >
      Custom Click Handler
    </button>
  );
}

NOTE: it is important that the button has className="relative"

🌐 SSR Compatibility

All hooks and utilities are designed to work seamlessly with server-side rendering:

Next.js Integration

// pages/_app.tsx or app/layout.tsx
import { useIsClient } from '@geee-be/react-utils';

function MyApp({ Component, pageProps }) {
  const isClient = useIsClient();

  return (
    <div>
      <Component {...pageProps} />
      {isClient && <ClientOnlyAnalytics />}
    </div>
  );
}

Hydration Safety

import { useLocalState, useIsClient } from '@geee-be/react-utils';

function ThemeProvider({ children }) {
  const [theme, setTheme] = useLocalState('theme', 'light');
  const isClient = useIsClient();

  // Prevents hydration mismatch
  const currentTheme = isClient ? theme : 'light';

  return (
    <div data-theme={currentTheme}>
      {children}
    </div>
  );
}

🎯 Performance Considerations

Optimized Re-renders

Hooks use React's built-in optimization patterns:

// useLocalState only re-renders when the actual value changes
const [count, setCount] = useLocalState('count', 0);

// Callbacks are memoized automatically
const increment = useCallback(() => setCount(c => c + 1), [setCount]);

Memory Management

Automatic cleanup prevents memory leaks:

// Broadcast channels are automatically cleaned up on unmount
const [message, postMessage] = useBroadcastChannel('channel');

// Event listeners are properly removed
const isMobile = useIsMobile();

📱 Framework Integration

Next.js

// Full SSR support with App Router
import { useLocalState } from '@geee-be/react-utils';

export default function Page() {
  const [data, setData] = useLocalState('page-data', null);
  return <div>{data?.title}</div>;
}

Remix

import { useIsClient } from '@geee-be/react-utils';

export default function RemixRoute() {
  const isClient = useIsClient();
  return isClient ? <ClientFeature /> : <ServerFallback />;
}

Vite/SPA

// Works great in client-side apps too
import { useHistoryState } from '@geee-be/react-utils';

function SinglePageApp() {
  const [route, setRoute] = useHistoryState('route', '/');
  return <Router currentRoute={route} />;
}

🔧 TypeScript Support

Full TypeScript support with comprehensive type definitions:

import { useLocalState } from '@geee-be/react-utils';

interface UserPreferences {
  theme: 'light' | 'dark';
  language: string;
  notifications: boolean;
}

function UserSettings() {
  // Type is automatically inferred as [UserPreferences, (value: UserPreferences) => void]
  const [prefs, setPrefs] = useLocalState<UserPreferences>('user-prefs', {
    theme: 'light',
    language: 'en',
    notifications: true
  });

  // TypeScript will ensure type safety
  const toggleTheme = () => {
    setPrefs(prev => ({
      ...prev,
      theme: prev.theme === 'light' ? 'dark' : 'light'
    }));
  };

  return <button onClick={toggleTheme}>Toggle Theme</button>;
}

🔗 Related Packages

📄 License

MIT License - see LICENSE file for details.

🐛 Issues & Support

Found a bug or need help? Please open an issue on GitHub.