Skip to content

Instantly share code, notes, and snippets.

@sagar-gavhane
Created November 7, 2018 07:21
Show Gist options
  • Select an option

  • Save sagar-gavhane/b91a2c77f82964dcf4e6cbf3fe1d68cd to your computer and use it in GitHub Desktop.

Select an option

Save sagar-gavhane/b91a2c77f82964dcf4e6cbf3fe1d68cd to your computer and use it in GitHub Desktop.
React suspense demo example created by me
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