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 🙏

© 2025 – Pkg Stats / Ryan Hefner

redux-sdk-pm-js

v1.0.0

Published

Reusable Redux SDK (JavaScript version)

Readme

🧠 redux-sdk-pm-js

redux-sdk-pm-js is a reusable, plug-and-play Redux SDK that provides a centralized and persistent state management solution for React and Next.js applications. It comes with a pre-configured Redux store, state persistence, and modular structure starting with a user module.


🚀 Key Features

  • ✅ Pre-wired Redux Store
  • ♻️ Session Persistence via sessionStorage
  • 🔍 Modular State Management (starting with user)
  • 📦 Easy Integration into any React/Next.js App

📁 Folder Structure

src/
├── api/                     # Axios instance for API calls
│   └── httpClient.js             # Axios instance definition
├── store/
│   ├── index.js             # Redux store setup, state persistence, cross-tab syncing
│   ├── rootReducers.js      # Combines reducers
│   └── user/                # User state module
│       ├── action.js        # Redux actions + SDK method (getUser)
│       ├── actiontypes.js   # Constants for actions
│       ├── reducer.js       # Redux reducer for user state
│       ├── selector.js      # Selectors for accessing user state
│       └── types.js         # Types for user state and actions
└── index.js                 # SDK public entry point + API export

🧩 Module: User

🔧 getUser() Function

await pravar_sdk.user.getUser();
  • Fetches mock user data (name, email)
  • Dispatches to Redux store
  • Accessible via selectors

🎯 Selectors

import { useSelector } from 'react-redux';
import {
  selectUser,
  selectUserName,
  selectUserEmail,
} from 'pravar_sdk/store/user/selector';

const user = useSelector(selectUser);         // Entire object
const name = useSelector(selectUserName);     // Only name
const email = useSelector(selectUserEmail);   // Only email

🏗️ Redux Store Setup

Store: src/store/index.js

  • Uses @reduxjs/toolkit's configureStore
  • Loads persisted state from sessionStorage
  • Saves new state on change
  • Exposes store and types
import { configureStore } from '@reduxjs/toolkit';
import rootReducer from './rootReducers';

const STORAGE_KEY = 'reduxSdkState';

const loadState = () => {
  try {
    const serializedState = sessionStorage.getItem(STORAGE_KEY);
    return serializedState ? JSON.parse(serializedState) : undefined;
  } catch {
    return undefined;
  }
};

const saveState = (state) => {
  try {
    const serializedState = JSON.stringify(state);
    sessionStorage.setItem(STORAGE_KEY, serializedState);
  } catch {}
};

export const listenToStorageChanges = (onChange) => {
  window.addEventListener('storage', (event) => {
    if (event.key === STORAGE_KEY) {
      const updatedState = event.newValue ? JSON.parse(event.newValue) : null;
      onChange(updatedState);
    }
  });
};

const preloadedState = loadState();

export const store = configureStore({
  reducer: rootReducer,
  preloadedState,
});

store.subscribe(() => {
  saveState(store.getState());
});

export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

export default store;

🧩 Integration in App

React

import { Provider } from 'react-redux';
import { store } from 'pravar_sdk';

<Provider store={store}>
  <App />
</Provider>

Next.js

Create _app.js:

import { Provider } from 'react-redux';
import { store } from 'pravar_sdk';

function MyApp({ Component, pageProps }) {
  return (
    <Provider store={store}>
      <Component {...pageProps} />
    </Provider>
  );
}

export default MyApp;

📦 Public SDK Entry (src/index.js)

export { store } from './store/index';
import { fetchAndSetUserInternal } from './store/user/action';

export const pravar_sdk = {
  user: {
    getUser: fetchAndSetUserInternal,
  },
};

🧱 Extend This SDK

To add another module (e.g., tickets, notifications):

  1. Create a folder under store/ like store/tickets/
  2. Add:
    • action.js
    • reducer.js
    • actiontypes.js
    • selector.js
    • types.js
  3. Add reducer to rootReducers.js:
    import ticketReducer from './tickets/reducer';
    
    const rootReducer = combineReducers({
      user: userReducer,
      tickets: ticketReducer,
    });
  4. Export new methods from SDK in src/index.js like:
    import { fetchTickets } from './store/tickets/action';
    
    export const pravar_sdk = {
      user: { getUser: fetchAndSetUserInternal },
      tickets: { getTickets: fetchTickets },
    };

💡 Switching to localStorage (Optional)

If you prefer localStorage over sessionStorage, update:

const STORAGE_KEY = 'reduxSdkState';
const serializedState = localStorage.getItem(STORAGE_KEY);
localStorage.setItem(STORAGE_KEY, serializedState);

Also update the storage listener to use localStorage instead.


🧪 Example

useEffect(() => {
  const fetch = async () => {
    const userData = await pravar_sdk.user.getUser();
    console.log('User Info:', userData);
  };
  fetch();
}, []);

✅ Summary

  • Easily reusable Redux SDK for any project
  • Built-in store, persistence, and sync
  • Scalable and extendable
  • Perfect for microfrontend or modular monorepo architecture