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-global-store

v1.0.2

Published

A simple global state solution for React

Downloads

296

Readme

React Global Store Build Status NPM Version Badge

A simple global state solution for React.

This library provides components which can be used to implement a simple global state store in your React project, without the complexity of frameworks like Redux.

Built on the React Context API, with Create React Context providing support for React 15.

Usage

Install

With NPM:

npm install react-global-store

Or, with Yarn:

yarn add react-global-store

Then, in your React application, you can import and use the two components:

Store Component

The <Store> component should wrap your application, and takes a value prop. This prop is an object containing all the content you would like to make available throughout your application.

import { Store } from 'react-global-store';

const content = {
  component: {
    text: 'Easy content management in React',
  },
};

const App = () => (
  <Store value={content}>
    <Component />
  </Store>
);

Content Component

Then, you can wrap any bit of your application with the <Content component in order to access that content. The <Content> component accepts the following props:

  • as: string used to choose what HTML tag to render the content in.
  • from: string used to pass the object key to the piece of content to use.
  • default: fallback content to be used if no content found with from key.

For example:

import { Content } from 'react-global-store';

const Component = () => (
  <Content
    as="p"
    from="component.text"
    default="Simple content management"
  />
);

Alternatively, the <Content> component takes a function as it's child, with the content made available as an argument. To access the content, you call the argument function - with the content key as the first argument, and then a fallback default as the second argument:

const Component = () => (
  <Content>
    {content => (
      <p>{content('component.text', 'Simple content management')}</p>
    )}
  </Content>
);

Running locally and testing

To run an interactive demo locally, you can run:

yarn run storybook

This will open a collection of demos on a local port.

Changes and history

See CHANGELOG.md.

Thanks

Big thanks to Jonathan Haines, the original creator of this project.