1×
Become a member
to unlock all features

Create egghead account to access 5000+ tutorials and resources from expert developers.

Create account
Autoplay

    Use a status enum instead of booleans

    reactReact

    Almost every UI app I've seen has an isLoading boolean somewhere in the code. And if it's not that, it's some variation of a boolean that's intended to represent some state. Unfortunately, very often this leads to states that exist in the real world that are unrepresentable in the code, or states in the code that are impossible in the real world. In either case, you've got yourself a bug.

    From this lesson you'll learn how to avoid this by using a status enum instead of an isLoading boolean in a React custom hook for retrieving the user's position via the geolocation API.

    This is based on my blog post: Stop using isLoading booleans.