1.1.7 • Published 5 years ago

unstated-connect2 v1.1.7

Weekly downloads
9
License
MIT
Repository
github
Last release
5 years ago

Unstated Connect2

Connect containers to components, without sacrificing performance.

This library basically combines together react-selectr, react-should-component-update and unstated-with-containers together.

Install

npm install --save unstated-connect2

API

connect ({
  container?: UnstatedContainer, // Single unstated container to connect
  containers?: UnstatedContainer[], // Array of unstated containers to connect
  shouldComponentUpdate?: rule | rule[], // Rule/rules to pass to `react-should-component-update`
  selector?: Function, // Selector function to pass to `react-selectr`
  pure?: false // Option to pass to `react-selectr`
})

Usage

import connect from 'unstated-connect2';
import MyContainer from './my_container';
import MyOtherContainer from './my_other_container';
import MyComponent from './my_component';

// The following code will:
// 1. Pass the value of `container` to `unstated-with-containers`, ensuring it gets connected
// 2. Pass the value of `shouldComponentUpdate` to `react-should-component-update`, ensuring unnecessary selections and re-renders are reduced
// 3. Pass the value of `selector` to `react-selectr`, ensuring MyComponent will only receive the selected props, minimizing unecessary re-renders

connect ({
  container: MyContainer,
  shouldComponentUpdate: 'path.to.relevant.prop',
  selector: ({ container }) => {
    foo: container.foo,
    bar: container.getBar ()
  }
})( MyComponent )

// If all you need is subscribing to one or multiple containers, you can simply write:

connect ( MyContainer )( MyComponent );
connect ( [MyContainer, MyOtherContainer] )( MyComponent );

Related

License

MIT © Fabio Spampinato

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago