The Boolean Explosion

Understand why independent boolean flags lead to unmaintainable 'Impossible States'.

State Management6 min readConcept 16 of 22

What is the Boolean Explosion?

When developers use multiple independent boolean flags to track application state (like isIdle, isLoading, isSuccess, isError), the total number of possible state permutations grows exponentially.

Just 4 independent booleans create $2^4 = 16$ possible state combinations! This exponential growth in complexity is known as the Boolean Explosion or 'Boolean Salad'.

The Impossible State Problem

Out of those 16 possible combinations, only 4 are actually logically valid (an app cannot be 'Idle' and 'Loading' at the same time).

This means 75% of your state space consists of 'Impossible States': combinations of variables that are syntactically allowed by the code, but logically contradictory to the business rules.

How do Impossible States Happen?

Impossible states occur due to uncoordinated state updates. When using independent useState hooks, setting one flag requires you to manually remember to reset all the others.

If an API request fails and you call setIsError(true) but forget to also call setIsLoading(false), your application is now permanently stuck in a contradictory state where it is both loading and erroring simultaneously.

Auto Demo: A Buggy Fetch Sequence

Tap the play button below to watch what happens when a developer forgets to clear the isLoading flag when setting isError to true. Watch the UI glitch out!

const [isIdle, setIsIdle] = useState(true); const [isLoading, setIsLoading] = useState(false); const [isError, setIsError] = useState(false); const fetchData = async () => { // 1. Start fetching
setIsIdle(false); setIsLoading(true);
try { await api.get(); setIsLoading(false); } catch (err) { // 2. OOPS! Forgot to setIsLoading(false)
setIsError(true);
} };
isIdle
true
isLoading
false
isError
false
Ready to fetch...

Uncoordinated setters create 'Impossible States', causing the UI to render both Loading and Error simultaneously.

Check yourself

Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.

  1. 1If a developer uses 5 independent boolean flags to track the status of a form submission, how many possible state combinations exist?

Remember this

  • Independent booleans cause the state space to explode exponentially ($2^n$).
  • Impossible states are valid syntactically but logically contradictory (e.g. isLoading: true and isError: true).
  • Uncoordinated state updates in useState are the primary cause of transient UI bugs.
  • Solve the boolean explosion by using explicit string literal statuses or Finite State Machines.

Done with this concept?

Mark it complete to track your progress. No login needed.