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-sharestate-hoc

v1.0.3

Published

A React higher-order component for share state using a Pub/Sub pattern

Downloads

9

Readme

react-sharestate-hoc

A React higher-order component for share state using a Pub/Sub pattern

Installation

$ npm install react-sharestate-hoc --save

Description

A React higher-order components, HOC, is a function that receive a React Component and return a enhance version.

With this module state of 1 component cam be share with n components. A 1 to n relationship. This is useful when a component state depends on state of another and there is not a parent relationship between them. This is usually done with Flux pattern but this time is solved with a minimal implementation of the Pub/Sub pattern using higher order React components.

Module contains two HOC, shareState and sharedState:

  • shareState is the component that share his state. Only can be one instance of it.
  • sharedState are subscribers of shareState components and can be many of them.

API

shareState

Share state of React component C, store is a empty object use for save the singleton instance of C and internal data

shareState(C, store)`

passed props

  • _setShareState is a callback function for set shared state
  • _shareStore is the store object

shareStateBind function

This is a helper function for "good looking" declaration of shareState components using ES.Next Function Bind Syntax

shareStateBind(C)

On this Example, declared share component function is use like a store too:

import { shareStateBind as shareState } from 'react-sharestate-hoc';

...
const SampleComponent = props => SampleComponent::shareState(<OneComponent {...props}/>);
...

sharedState

Subscribe to a component that share his state, many can subscribe to same. C is the component to be wrapped. prop is a custom prop string name used for pass share state singleton store object, this prop connect a shareState component with sharedState components.

sharedState(C, prop)

passed props

  • sharedComponent default prop string name of shareState store object
  • _instance instance of share state component
  • _shared shared state component

getComponentInstance function

A helper function that return a promise of a share Component instance. This could be useful if needed create a custom sharedState HOC.

getComponentInstance(store, ms)

Contributing

  • Documentation improvement
  • Feel free to send any PR

LICENSE

MIT