Skip to content

Instantly share code, notes, and snippets.

@rayrayzayzay
Created July 18, 2022 23:19
Show Gist options
  • Save rayrayzayzay/a8c6f18ab3786e2da5fb005ccfa1f197 to your computer and use it in GitHub Desktop.
Save rayrayzayzay/a8c6f18ab3786e2da5fb005ccfa1f197 to your computer and use it in GitHub Desktop.
❌ The complex component got even more complex
function UserProfile({request}:
{request: MyProfileRequest}) {
// 🤞 let's hope this boolean
combination is right
if (request.isLoading && !request.data &&
!request.errorMessage) {
return <Spinner />
}
if (request.data) {
return (<UserProfileCard
isLoading={request.isLoading}
user={request.data}
/>)
}
// still hope we get both of these here!
if (request.errorMessage && request.statusCode) {
return (<>
<ErrorMessage
code={request.statusCode}
message={request.errorMessage}
/>
{request.isLoading && <Spinner />} //
nested conditions are a bit unpleasant
</>)
}
// I hope we don't get here
return null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment