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-context-redux

v0.3.0

Published

A Redux style wrapper over React's Context API

Downloads

13

Readme

react-context-redux

NPM version Build Status Dependency Status

A Redux style wrapper over React's new Context API.

Installation

Just like React, react-context-redux also can be used through both NPM and <script> tag

npm i react-context-redux --save
<script src="https://unpkg.com/react-context-redux/umd/react-context-redux.min.js" crossorigin></script>

Or use it with a specific version you need

<script src="https://unpkg.com/[email protected]/umd/react-context-redux.min.js" crossorigin></script>

Usage

You can use it the same way as redux provider and connect. Dispatch will be available as a prop by default when connect is used.

store.js

import { createStore } from 'react-context-redux';

export const { Provider, connect } = createStore({ // pass your initial state
  like: {
    count: 0
  }
});

It has middleware support too, works the same way as how redux middleware works. Just import applyMiddleware, include your favorite middlewares as parameters and pass it to createStore, and it will work like a charm.

import { createStore, applyMiddleware } from 'react-context-redux';
import logger from 'redux-logger';

const { Provider, connect } = createStore({someState: 'value'}, applyMiddleware(logger));

App.js:

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from './store';
import LikeButton from './LikeButton';

const App = () => (
  <Provider>
    <LikeButton />
  </Provider>
);

ReactDOM.render(<App />, document.getElementById('counter_container'));

LikeButton.js:

import React from 'react';
import { connect } from './store';

const increaseCount = value => {
  // while dispatching we expect to things two be present in the param object
  // key - path to be updated in state ( separated by . )
  // payload - value to be put on that path
  // if some keys specified in the path are not available we will create them
  return dispatch => {
    dispatch({
      key: 'like.count',
      payload: value
    });
  };
};

const LikeButton = ({ count, dispatch }) => (
  <button onClick={() => dispatch(increaseCount(count + 1))} type="button">
    {/* We have a redux-thunk like approach where you param for dispatch  is a function */}
    Liked {count} times
  </button>
);

const select = state => {
  return {
    count: state.like.count
  };
};

export default connect(select)(LikeButton);

Note: While using react-context-redux through a script tag, make sure to wrap the provider

index.js

class ProviderWrapper extends React.Component {
  render() {
    return e(Provider, this.props);
  }
}

ReactDOM.render(
  e(ProviderWrapper, {}, e(connect(select)(LikeButton))),
  document.getElementById('counter_container')
);

Examples

See /examples folder for more examples

Contribution

Contributions are awesome. Go through our Contribution Guide to get started.

LICENSE

MIT