ReSift icon indicating copy to clipboard operation
ReSift copied to clipboard

Checking and manipulating status

Open ricokahler opened this issue 6 years ago • 0 comments

I have an issue with the naming of our helper functions isNormal, isLoading etc.

The prefix is is where I have the issue. The function isNormal does not check if the status is exactly normal, instead checks to see if that status contains normal.

So let's rename it? 🤔

isNormal => hasNormal

function Component() {
  const [data, status] = useFetch(myFetch):
  return <>
    {hasLoading(status) && <Spinner />}
    {hasNormal(status) && <>{data.stuff}</>}
  </>;
}

I think this helps communicate to our users that statuses are a collection of booleans vs a mutually exclusive state.


Manipulating a status (to force a certain status for the loader for example), currently requires some knowledge about bitwise operators which not great. Instead it would be better if we has manipulation methods like addNormal, removeNormal or similar.

Alternatively we could add a function addStatus(status, NORMAL) to reduce the API footprint.

ricokahler avatar Oct 11 '19 15:10 ricokahler