Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »

proppy-react

1.2.6 • Public • Published

proppy-react

npm

React integration package for ProppyJS


Guide

Installation

With npm:

$ npm install --save proppy react proppy-react

Via unpkg CDN:

<script src="https://unpkg.com/proppy@latest/dist/proppy.min.js"></script>
<script src="https://unpkg.com/proppy-react@latest/dist/proppy-react.min.js"></script>
 
<script>
  // available as `window.ProppyReact`
</script> 

Usage

First, setup your root component with providers data:

// components/Root.js
import React from 'react';
import { ProppyProvider } from 'proppy-react';
 
import MyComponent from './MyComponent';
 
const providers = {
  foo: 'foo value',
};
 
export default function Root() {
  return (
    <ProppyProvider providers={providers}>
      <MyComponent />
    </ProppyProvider>
  );
}

Now anywhere from your components tree, you can use the attach higher-order component:

// components/MyComponent.js
import React from 'react';
import { compose, withProps } from 'proppy';
import { attach } from 'proppy-react';
 
const P = compose(
  withProps((props, providers) => ({
    foo: providers.foo,
  })),
  withProps({ bar: 'bar value' }),
);
 
function MyComponent(props) {
  const { foo, bar } = props;
 
  return <p></p>;
}
 
export default attach(P)(MyComponent);

API

ProppyProvider

For setting providers at React's context-level.

Example:

import React from 'react';
import { ProppyProvider } from 'proppy-react';
 
export default function Root() {
  return (
    <ProppyProvider providers={providers}>
      <SomeOtherComponent />
    </ProppyProvider>
  );
}

attach

attach(P)(Component)

Higher-order component for attaching your Proppy factory to your Component.

Keywords

install

npm i proppy-react

Downloadsweekly downloads

441

version

1.2.6

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability