I review a lot of component code. The most common bug pattern I see is not a typo. It is this:
const [ isLoading , setIsLoading ] = useState ( false ) ; const [ isError , setIsError ] = useState ( false ) ; const [ isSuccess , setIsSuccess ] = useState ( false ) ;
Enter fullscreen mode
Exit fullscreen mode
Three booleans, eight combinations, three of which are legal. The other five are bugs waiting for a slow network.
Why the bug is structural, not careless
Everyone knows not to set isLoading and isSuccess at the same time. Nobody sets them deliberately. They happen because the flags are set in different places, on different async paths, sometimes in an await that resolves after the component re-rendered.
Add a quantity and a retryCount and the handshake gets worse.…