DEV Community


Discussion on: Status instead of isLoading boolean?

larsejaas profile image

It might be great for some situations but more verbose for others...

Let me explain.

Normally (in React, but I guess it would be almost the same elsewhere) I would import the fetch logic like this:

const [isLoading, Data, isError, Error] = GetData(URL)

Then in the JSX:

{!!isLoading ?
(<div>Data is Loading</div>)
(<div>Something went wrong</div>)
Enter fullscreen mode Exit fullscreen mode

My point is that the booleans make it possible to use really short syntax.

I definitely see your point when status could have a lot of different states, but if you have a lot of different skeleton loaders and stuff I think booleans are hard to beat.

why not return the different states like booleans?

something along the lines:

const [iddle, resolved, rejected] = GetData(URL)
Enter fullscreen mode Exit fullscreen mode
Forem Open with the Forem app