DEV Community

Discussion on: Avoiding large ternary operator statements in React

Collapse
 
pengeszikra profile image
Peter Vivo • Edited

I do not prefered wrappers, so:

const Example = () => {
  const { data, status } = useQuery('users', fetchUsers)

  return (
    <Page>
      {status === Status.LOADING && <LoadingView />}
      {status === Status.SUCCESS && <SuccessView data={data} />}
      {status === Status.ERROR   && <ErrorView />}
    </Page>
  )
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
joolsmcfly profile image
Julien Dephix

+1 it’s more readable and succinct

Collapse
 
gax97 profile image
Danilo Gačević

I agree that this is a highly opinionated approach :)

Collapse
 
nandokferrari profile image
Fernando Ferrari

That is my choice too!