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

unifyedx-reactutils

v2.1.11

Published

**License**: MIT

Downloads

94

Readme

unifyedx-reactutils

License: MIT

A collection of useful utilities and helper functions for React applications, including methods for session and local storage management, cookie handling, lodash functions, common websocket and more...

Features

  • Utility Functions: Methods to manage cookies, session storage, local storage.
  • Lodash Integration: Exposes all Lodash methods for easy use.
  • TypeScript Support: Includes types for all utility functions.
  • Tree Shaking: Optimized for minimal bundle size using Webpack's tree shaking feature.
  • Bundled with Webpack: Configured for easy integration into any React project.

Key Points for web socket supporting both Socket.IO-based real-time communication and a native WebSocket-based solution within the same library:

Socket.IO setup:

  • SocketIOProvider: Context provider that initializes a Socket.IO client.
  • useSocketIO: Hook to access the Socket.IO client instance.
  • useSocketIOEvent: Hook to listen to Socket.IO events.
  • useSocketIOEmit: Hook to emit Socket.IO events.

Native WebSocket setup:

  • WebSocketProvider: Context provider that initializes a native WebSocket connection.
  • useWebSocket: Hook to access the native WebSocket instance.
  • useWebSocketMessage: Hook to listen for incoming messages.
  • useWebSocketSend: Hook to send messages through the WebSocket.

Installation

To install the library, simply run:

npm install unifyedx-reactutils

Usage

Importing the library You can import the library in your React project to access its utilities:

import {
  setSessionStorage,
  getSessionStorage,
  removeSessionStorage,
  setLocalStorage,
  getLocalStorage,
  removeLocalStorage,
  setCookie,
  getCookie,
  deleteCookie,
  debounce,
} from 'unifyedx-reactutils';

Usage Examples

  1. Managing Session and Local Storage
// Set, get, and remove session storage
setSessionStorage('key', 'value');
const sessionValue = getSessionStorage('key');
removeSessionStorage('key');

// Set, get, and remove local storage
setLocalStorage('key', 'value');
const localValue = getLocalStorage('key');
removeLocalStorage('key');
  1. Cookie Handling
// Set, get, and delete cookies
setCookie('cookieName', 'cookieValue', { path: '/', maxAge: 3600 });
const cookieValue = getCookie('cookieName');
deleteCookie('cookieName');
  1. Debounce utility
import { debounce } from 'unifyedx-reactutils';

// Example of using debounce utility for a function
const debouncedFunc = debounce(() => {
  console.log('Function debounced');
}, 300);

// Call the debounced function
debouncedFunc();
  1. Using Socket.IO
import React from 'react';
import {
  SocketProvider,
  useSocketEvent,
  useSocketEmit,
} from 'unifyedx-reactutils';

const MyComponent = () => {
  const message = useSocketEvent < string > 'chat-message';
  const emit = useSocketEmit();

  return (
    <div>
      <h1>Chat Messages</h1>
      {message && <p>New message: {message}</p>}
      <button onClick={() => emit('chat-message', 'Hello from Microfrontend')}>
        Send Message
      </button>
    </div>
  );
};

const App = () => {
  return (
    <SocketProvider
      url="https://your-socket-server.com"
      options={{ auth: { token: 'Bearer my-token' } }}
    >
      <MyComponent />
    </SocketProvider>
  );
};

export default App;
  1. Using Native WebSocket:
import React from 'react';
import {
  WebSocketProvider,
  useWebSocketMessage,
  useWebSocketSend,
} from 'unifyedx-reactutils';

const WebSocketExample = () => {
  const message = useWebSocketMessage();
  const send = useWebSocketSend();

  return (
    <div>
      <h2>Native WebSocket Echo</h2>
      <p>Received: {message}</p>
      <button onClick={() => send('Hello WebSocket')}>
        Send WebSocket Message
      </button>
    </div>
  );
};

const App = () => (
  <WebSocketProvider url="wss://ws.postman-echo.com/raw">
    <WebSocketExample />
  </WebSocketProvider>
);
// Method 1: If you want to pass the token then use
<WebSocketProvider url={`wss://example.com/socket?token=${yourToken}`}>
  <YourComponent />
</WebSocketProvider>;

//Method 2: to pass auth token as soon as the connection is successful
React.useEffect(() => {
  // Once the socket is open, send auth token
  if (socket && socket.readyState === WebSocket.OPEN) {
    send(JSON.stringify({ type: 'auth', token: yourToken }));
  }
}, [socket, send]);
  1. Organized constant for api and non-api:
 - Separation of Concerns: Keeps API and non-API constants logically grouped.

- Scalability: Adding new MFEs or updating constants is straightforward.

- Discoverability: Consumers can easily find constants relevant to their MFE.

- Modular Imports: Consumers can import only the constants they need, reducing unused imports.