Skip to content

Instantly share code, notes, and snippets.

@dsvgit
Last active May 6, 2022 18:11
Show Gist options
  • Save dsvgit/fca793a0a65ea43566446fa549e41e18 to your computer and use it in GitHub Desktop.
Save dsvgit/fca793a0a65ea43566446fa549e41e18 to your computer and use it in GitHub Desktop.
React. Self-Invoking Functions for rendering.
const SelfInvokingChildren = () => {
const [loading, error, data] = useData()
return (
<Layout>
{(function () {
if (loading) return <Placeholder />
if (error) return <Error />
if (!data) return <NotFound />
return <PageContent data={data} />
})()}
</Layout>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment