0.2.0 ā€¢ Published 4 years ago

react-suspendable-contract v0.2.0

Weekly downloads
59
License
MIT
Repository
github
Last release
4 years ago

React Suspendable Contract

Enjoy React Suspense for async data fetching without rewriting existing components.

This module provides a simple wrapper <Suspendable> and a simple hook useSuspendableData(..) to fulfill the Suspense data fetching contract.

[Experimental]: React.Suspense for data fetching is under experimental mode! (even React 17.0)

Getting Start

yarn add react-suspendable-contract

# OR

npm install --save react-suspendable-contract

Support

āœ… Typescript support

Example

import { Suspendable, useSuspendableData } from 'react-suspendable-contract'

const UserPage = ({ userId }) => {
  const suspendableData = useSuspendableData(() => getUserAsync({ id: userId }), [userId])

  return (
    <Suspense fallback={<Loading />}>
       <Suspendable data={suspendableData}>
         {data => <UserProfile user={data}/>}
       </Suspendable>
    </Suspense>
  )
}

License

MIT

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.1.0-alpha.1

4 years ago

0.1.0-alpha.0

4 years ago