A common case of needless state: Dialog visibility


A common case of needless state: Dialog visibility.

Example: If a dialog displays when I click on a user, I only need one piece of state, not two.

And this can be streamlined even further.

Here, assume UserDialog only renders when provided a user. UserDialog simply returns null if no user is provided.

This streamlined state also avoids bugs.

For example, what would happen if showDialog is true, but selectedUser is null? That's confusing, and hints at a bug.

The solution? Eliminate needless state.

Make impossible state combinations impossible.

View original on X