react-to-component
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

react-to-component

Travis npm package Coveralls semantic-release

🚀 Blazing fast and tiny library that enables you to create react components (componentify) imperative or functional apis.

Install

yarn add react-to-component

Aims to be:

  • 🚀 Blazing fast
  • ➿Defensive code friendly
  • :rage2: Async first
  • 🔧 Memory leak safe
  • 💍 Test friendly

A quick example

<ToComponent original={oldLegacyCodeApi} params={[1, 2, 3]}>
  {({ loading, error, data }) =>
    loading ? "Loading" : error ? "Oops, error" : JSON.stringify(data)
  }
</ToComponent>

Live examples

  • #### Async example Edit react-to-component async example

Configuration

Prop Required Default Type Description
original ✔️ ✖️ (...params: P[]) => Promise<T> or T The original function to be encapsulated
params ✔️ ✖️ P[] The params that will be used in the function invocation
children ✔️ ✖️ ({ data: T or null, error: Error or null, loading: boolean }) => JSX.Element or JSX.Element[] or null The render prop that controls you data flow
parametersDidChange ✖️ Params equality (previousParams: P[], nextParams: P[]) => boolean Ability to supply a custom check for parameter equality, use this if for example you need to ignore some parameters for caching purposes

Package Sidebar

Install

npm i react-to-component

Weekly Downloads

5

Version

1.0.2

License

MIT

Unpacked Size

43.9 kB

Total Files

15

Last publish

Collaborators

  • diogofcunha