Created
November 18, 2019 09:30
-
-
Save yarastqt/3de6287a941d7bb8f5260e1f7d7095c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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