Skip to content

Instantly share code, notes, and snippets.

@kaineer
Created October 21, 2024 09:02
Show Gist options
  • Save kaineer/2b55bd506ea32a68c4d68d96314b4e76 to your computer and use it in GitHub Desktop.
Save kaineer/2b55bd506ea32a68c4d68d96314b4e76 to your computer and use it in GitHub Desktop.
interface LazyProps {
condition: boolean;
render: () => React.ReactNode;
fallback?: () => React.ReactNode;
}
export const LazyWhen = ({ condition, render, fallback }: LazyProps) => {
if (condition) {
return render();
}
return fallback ? fallback() : null;
}
export const LazyWaiting = ({ condition, render }: Omit<LazyProps, "fallback">) => {
if (condition) {
return render();
}
return <Spinner />;
}
// Как вариант можно переделать на
// <When condition={ ... } render={renderFunction} fallback={somespinnerFunction} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment