Created
November 7, 2018 07:21
-
-
Save sagar-gavhane/b91a2c77f82964dcf4e6cbf3fe1d68cd to your computer and use it in GitHub Desktop.
React suspense demo example created by me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Suspense } from "react"; | |
| import { createCache, createResource } from "simple-cache-provider"; | |
| const cache = createCache(); | |
| const readText = createResource((text) => { | |
| return new Promise((resolve, reject) => { | |
| setTimeout(() => { | |
| resolve(text); | |
| }, 1000); | |
| }); | |
| }, (text) => text); | |
| const AsyncText = (props) => { | |
| const data = readText.read(cache, props.text); | |
| return ( | |
| <span>{data}</span> | |
| ); | |
| } | |
| const PlaygroundComponent = (props) => { | |
| return ( | |
| <div> | |
| <h2>Playground Component Works!!!</h2> | |
| <Suspense maxDuration={2000} fallback={<p>Loading...</p>} > | |
| <AsyncText text="wofooooooooooooo!!!" /> | |
| </Suspense> | |
| </div> | |
| ); | |
| }; | |
| export default PlaygroundComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment