react-async-child
React Component to render asynchronously.
Usage
import React PropTypes from 'react';import AsyncChild from 'react-async-child';import Example from './Example'; const Demo = <AsyncChild> <Example =/> </AsyncChild>;
Examples
Destructuring
<AsyncChild> <Example /> </AsyncChild>
Try / catch
<AsyncChild> let view; try view = <Example =/>; catch error view = <div> errormessage </div>; return view; </AsyncChild>
Without async/await syntax, using a Promise
<AsyncChild> </AsyncChild>
React Router v4 async route with transition
Here we return an <AsyncChild/>
component in a React Router <Match/>
children prop. When the route is matched, it will wait for the db.find()
async function and then render the result. If the route changes, it will wait again, and rerender again. This will make the transition trigger only after the async function is complete.
const MyAsyncView = components <Match ='/some/:id' = />;
Props
children
- required: true
- type: func
An async function that returns a React element.
default
- required: false
- type: node
A React element to render until the async function has not been resolved.