Created
October 21, 2024 09:02
-
-
Save kaineer/2b55bd506ea32a68c4d68d96314b4e76 to your computer and use it in GitHub Desktop.
This file contains 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
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