B
B
beduin012021-11-25 09:56:02
React
beduin01, 2021-11-25 09:56:02

How to manage interface states?

A question. What is the way to handle all possible interface states?
I mean the state:
isLoading
isSuccess
isEmpty

Plus, I always add the errorText state here in case of an error.

How to process all this correctly? At the moment I'm just arranging the if string.

Maybe there is some pattern or something else for this case?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexandroppolus, 2021-11-25
@Alexandroppolus

You can use a nested ternary. You can't imagine anything more compact anyway.

return isEmpty ? <Empty /> : isLoading ? <Loading /> : errorText ? <Error text={errorText} /> : <ShowSuccessData ... />

I
Ilya Olovyannikov, 2021-11-25
@cannibal_corpse

[state, setState] = useState(false);


  return (
    {state && <Component/>}
  )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question