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

ez-react-redux

v0.2.1

Published

No...no...noπŸ™…β€β™‚οΈπŸ™…β€β™€οΈ, `ez-react-redux` is a **_bad_** patternπŸ‘ŽπŸ‘ŽπŸ‘Ž!

Downloads

5

Readme

ez-react-redux User Guide

No...no...noπŸ™…β€β™‚οΈπŸ™…β€β™€οΈ, ez-react-redux is a bad patternπŸ‘ŽπŸ‘ŽπŸ‘Ž!

You shouldn't use it in any productions.

But it's a life saver in small projects.

  • No reducers(out of the box)
  • Immediately update your state any time any where without the hindrance of reducers
  • Get rid of immutable, immer is internally embeded
  • useSelector supported
  • No React Context

And it also has the following features:

  • Support multiple store instances
  • Support redux ecosystem(like redux-logger)
  • Support Typescript
  • Very small size Bundle Size

EZ at a Glance

// Follow a property
const count = useSelector(store, state => state.count);

// Update a property
store.dispatch({
  type: 'add',
  updater(state) {
    state.count += 1;
  },
});

Working example

import { createStore, useSelector } from 'ez-react-redux';

type State = {
  count: number;
};

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

const store = createStore<State>(initialState);

function MyComponent() {
  const count = useSelector(store, state => state.count);

  function add() {
    store.dispatch({
      type: 'add',
      updater(state) {
        state.count += 1;
      },
    });
  }

  return (
    <div>
      <h1>{count}</h1>
      <button type="button" onClick={add}>
        +
      </button>
    </div>
  );
}

API Reference

import { Action, StoreEnhancer, Store } from 'redux';
/**
 * Updater is a function that describes how to update state.
 * @template S The type of the whole state
 */
export declare type Updater<S = any> = (state: S) => void;
/**
 * EZAction is the only action type for `ez-react-redux`
 * @template S The type of the whole state
 */
export interface EZAction<S = any> extends Action {
  updater?: Updater<S>;
}
/**
 * Create the store instance
 * @template S The type of the whole state
 */
export declare function createStore<S = any>(
  initialState: S,
  enhancer?: StoreEnhancer
): Store<S, EZAction<S>>;
/**
 * Property selector
 * @template S The type of the whole state
 */
export declare type Selector<S = any, T = unknown> = (state: S) => T;
/**
 * Property selector for React hooks
 * @template S The type of the whole state
 * @template T The type of the selected property
 */
export declare function useSelector<S = any, T = unknown>(
  store: Store<S>,
  selector: Selector<S, T>
): T;