Pray
React asynchronous components:
// Books.js;; // Wrap the async component in pray:async { const books = await ; return <ul> books </ul> };
Then in your main code import and use it as usual:
// App.js;; <Books />;
Spinner
You can add a spinner for whenever the main component is still loading:
//const Spinner = 'Loading...'; // Note that we pass the component, not the instance:Spinner async { ...};
You can also assign it on render time:
// App.jsconst Spinner = "Loading..."; // We again pass the component, not the instance: <Books fallback=Spinner />;
Props
Props will be passed as expected:
// Book.jsasync { const book = await ; return <div>booktitle</div>;}; // App.js <Book id=123 />;
None of the Hooks can be used within async components. Please call those above and pass them as props:
const Books = ; const BookList = { const books setBooks = ; return <div> Book count: bookslength <Books fallback= 'Loading...' onLoad=setBooks /> </div> ;};