1.2.1 • Published 2 years ago

react2angular-shared-context v1.2.1

Weekly downloads
84
License
MIT
Repository
github
Last release
2 years ago

react2angular-shared-context

Share context between React components in react2angular.

NPM JavaScript Style Guide

Install

npm install --save react2angular-shared-context

Usage

import { react2angular } from 'react2angular';
import React, { FunctionComponent } from 'react'
import { ProviderAbc, ConsumerAbc } from './context/abc'

import createSharedContext from 'react2angular-shared-context'

// Root component with context providers
const Root: FunctionComponent<{foo: number}> = ({foo, children}) => (
  <ProviderAbc foo={foo}>
      {children}
  </ProviderAbc>
);

// Example component that consumes providers defined in Root component
const MyExample: FunctionComponent<{bar: string}> = ({bar}) => (
  <ConsumerAbc>
    {({a, b, c}) => <p>{bar} says: {a} x {b} = {c}</p>}
  </ConsumerAbc>
);

// Create shared context instance
const sharedContext = createSharedContext(Root);

// Define shared context component first
// This component can be optionally wrapped in react-hot-loader
angular
  .module('example')
  .component('sharedContextReact', react2angular(sharedContext.component, ['foo']));

// Wrap example component with shared context
// Do not wrap this component with react-hot-loader because the shared context instance will already handle this
angular
  .module('example')
  .component('myExampleReact', react2angular(sharedContext.use(MyExample), ['bar']));

License

MIT © https://github.com/seahorsepip

1.2.0

2 years ago

1.2.1

2 years ago

1.1.2

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago