Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-use-sub

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-sub

Subscription based lightweight React store

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
878
increased by13.44%
Maintainers
1
Weekly downloads
 
Created
Source

GitHub license styled with prettier

react-use-sub

Subscription based lightweight React store.

How it looks:

// >>> in your store.js
import { createStore } from 'react-use-sub';

const initialState = { foo: 'bar' };
export const [useSub, Store] = createStore(initialState);

// >>> in any component
import { useSub } from '/path/to/store.js';

export const App = () => {
    // subscribe here your custom store mapper
    const { fooLength } = useSub(({ foo }) => ({ fooLength: foo.length }));
    
    return <div>Foo has length: {fooLength}</div>;
}

// >>> in any other (or same) place
import { Store } from '/path/to/store.js';

// signature equally to the Setter function of useState
Store.set({ foo: 'something' });
// this updates the stored data
expect(Store.get()).toEqual({ foo: 'something' });
// and updates all components that would be passed
// different values from the subscribed store mapper

My Goals:

  • No context
  • TypeScript support
  • Flow support
  • Very small package size (< 1kB gzipped)
  • No dependencies
  • Very easy to use
  • Much better performance than React-Redux
  • Scalability

Treat-offs:

  • You need React v16.8 or greater (hook support)
  • It does not work for class components

Keywords

FAQs

Package last updated on 30 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc