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.1.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

GitHub license styled with prettier

react-use-sub

WIP: 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 (513 bytes)
  • No dependencies
  • Very easy to use
  • Better performance than React-Redux
  • Scalability

Treat-offs:

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

Keywords

FAQs

Package last updated on 02 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