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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-store-explorer

v2.1.3

Published

inspect, visualise and track store built with zustand, redux, get-set-react.etc. this dev tools package lets you explore store in your react app.

Downloads

35

Readme

Dev tools for zustand, redux and get-set-react

This library helps you visualise, log, debug, track state of any react application that uses zustand, redux or get-set-react. This opens dev tools inside the app so you don't need to open console to see what the state is.

Simply use at app level in order to render dev tools. press Esc key to open it or you can click on the three dot icon.

you can control on which environment or domain you want to render these dev tools.

using with zustand

stackblitz demo link: https://stackblitz.com/edit/vitejs-vite-3nn61v?file=src%2FApp.tsx

import { create, useStore } from "zustand";
import { StoreExplorer } from "react-store-explorer";

const store = create(() => ({ count: 0 }));

const incr = () => {
  store.setState((s) => ({ count: s.count + 1 }));
};
const stores = { store };

function App() {
  const { count } = useStore(store);
  return (
    <StoreExplorer
      stores={stores}
      iconColor={"green"}
      from={"zustand"}
      enableDevTools={true}
    >
      <div className="card">
        <button onClick={() => incr()}>count is {count}</button>
      </div>
    </StoreExplorer>
  );
}

export default App;

Installation

To install React Store Explorer in your project, use npm or yarn:

npm install react-store-explorer

or

yarn add react-store-explorer

using with get-set-react

Stackblitz example: https://stackblitz.com/edit/vitejs-vite-gdbvx9?file=src%2FApp.tsx

import { create, useGet } from "get-set-react";
import { StoreExplorer } from "react-store-explorer";

const store = create({ count: 0 });

const incr = () => {
  store.update((s) => s.count++));
};
const stores = { store };

function App() {
  const { count } = useGet(store);
  return (
    <StoreExplorer
      stores={stores}
      iconColor={"green"}
      enableDevTools={true}
    >
      <div className="card">
        <button onClick={() => incr()}>count is {count}</button>
      </div>
    </StoreExplorer>
  );
}

export default App;

using with redux

stackblitz demo link: https://stackblitz.com/edit/vitejs-vite-jqw6dq?file=src%2FApp.tsx

import React from "react";
import { createStore } from "redux";
import { Provider, useSelector, useDispatch } from "react-redux";
import { StoreExplorer } from "react-store-explorer";

// Action Types
const INCREMENT = "INCREMENT";
const DECREMENT = "DECREMENT";

// Action Creators
const increment = () => ({ type: INCREMENT });
const decrement = () => ({ type: DECREMENT });

// Initial State
const initialState = {
  count: 0,
};

// Reducer
const counterReducer = (state = initialState, action: { type: string }) => {
  switch (action.type) {
    case INCREMENT:
      return { ...state, count: state.count + 1 };
    case DECREMENT:
      return { ...state, count: state.count - 1 };
    default:
      return state;
  }
};

// Store
const store = createStore(counterReducer);

// Counter Component
const Counter = () => {
  const count = useSelector((state: { count: number }) => state.count);
  const dispatch = useDispatch();

  return (
    <div style={{ textAlign: "center", marginTop: "50px", width: "100%" }}>
      <h3>Counter: {count}</h3>
      <button
        onClick={() => dispatch(increment())}
        style={{ fontSize: "20px", marginRight: "10px" }}
      >
        +
      </button>
      <button
        onClick={() => dispatch(decrement())}
        style={{ fontSize: "20px", marginLeft: "10px" }}
      >
        -
      </button>
    </div>
  );
};

// App Component
const App = () => {
  return (
    <Provider store={store}>
      <StoreExplorer stores={{ store }} from="redux">
        <Counter />
      </StoreExplorer>
    </Provider>
  );
};

export default App;

Features

  • State Inspection: Visualize the current state of your application, with support for complex nested objects and arrays.
  • Change Logging: Keep track of state changes and view a log of modifications, additions, and deletions.
  • Previous State Views: Access the history of previous states and inspect how state evolved over time.

DevTools Integration

The explorer includes a collapsible interface and logs for state changes. When enabled, you can toggle the interface by clicking an icon that appears in the corner of the window. To open or close the panel programmatically, use the keepOpen prop.

<StoreExplorer keepOpen={true} />

API

StoreExplorer

Props:

  • stores: An object containing your application's stores, where each store must have getState() and subscribe() methods.
  • iconColor: string: css color value to customise the icon's color
  • hideIcon : boolean: to hide the icon, you can use esc key to show or hide the panel.
  • XIconPosition : { bottom: "50px", right: "50px" } : to position the icon.
  • from : 'zustand' | 'redux' | 'get-set-react' (default)
  • keepOpen: boolean : to keep the panel open by default.
  • maxLogCount: number : of state changes to store in the log history.
  • hideIcon: boolean : Option to hide the toggle icon. when icon is hidden, press 'Esc' key to toggle open.
  • disableToggleESCKey: boolean: Disables the ESC key for toggling the interface.

Development

To contribute to React Store Explorer, clone the repository and install dependencies:

git clone https://github.com/thejsmaster/react-store-explorer
cd react-store-explorer
npm install

to build the package:

npm run build

License

This project is licensed under the MIT License.