1.0.1 • Published 5 years ago

@scottmunday84/react-consumer v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

react-consumer npm version

A simple approach to responding from a React context through a quick consumer.

Installation and use

Install npm packages:

yarn install -S @scottmunday84/react-consumer

And to use:

import store from '../reducers/store';
import Consumer from '@scottmunday84/react-consumer';
import React from 'react';

const Layout = () => {
  const map = ({state, dispatch}) => {
    return {
      foo: state.foo,
      dispatchFoo: payload => dispatch('ACTION_FOO', payload)      
    };
  };
    
  return (
    <Consumer store={store} map={map}>
      {({foo, dispatchFoo}) => <button onClick={() => dispatchFoo(!foo)}>Dispatch Foo</button>}
    </Consumer>);
};

export default Layout;

Happy coding!