Skip to content

Instantly share code, notes, and snippets.

@yarastqt
Created November 18, 2019 09:30
Show Gist options
  • Save yarastqt/3de6287a941d7bb8f5260e1f7d7095c9 to your computer and use it in GitHub Desktop.
Save yarastqt/3de6287a941d7bb8f5260e1f7d7095c9 to your computer and use it in GitHub Desktop.
type LoaderProps<T> = {
fetching: boolean
data: T
}
const Loader: FC<LoaderProps> = ({ fetching, data, children }) => (
if (fetching) {
return <div>Loading...</div>
}
return children(data)
)
const App = () => (
// Data maybe undefined
<Loader fetching={true} data={data}>
// Data should be defined
{data => <div>{data}</div>}
</Loader>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment