Skip to content

Instantly share code, notes, and snippets.

@chamerling
Created December 16, 2022 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamerling/c55af57c28de03e48c5eaf15333cbb0a to your computer and use it in GitHub Desktop.
Save chamerling/c55af57c28de03e48c5eaf15333cbb0a to your computer and use it in GitHub Desktop.
import { useState, useEffect, useCallback } from "react";
import { withWebPerformance } from "./withWebPerformance";
import Loader from "./components/Loader";
export default function SomeComponent() {
const LoaderWithPerformance = withWebPerformance(Loader, "web-perf");
const [loading, setLoading] = useState(true);
// ...
// TODO: load something and update the loading state
//
// callback when loader is complete
const onLoaded = useCallback((measure: PerformanceMeasure) => {
setLoadingTime(measure.duration);
}, []);
return (
<div className="App">
{loading ? (
<LoaderWithPerformance onLoaded={onLoaded} />
) : (
<div>
{ /* ... */ }
</div>
)}
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment