layman/terms
Inside an app

State

stayt

In shortEverything an app is keeping track of at a given moment: what's in your basket, which tab is open, what you've typed.

Close a book and open it later: the bookmark tells you where you were. Apps need to remember things like that too.

You’re halfway through a novel. You close it and come back tomorrow. The bookmark tells you exactly where you were. Without it, you’d have to find your place all over again.

In an app, state is the bookmark and much more. It’s everything the app is keeping track of right now: what’s in your basket, which page you’re on, what you’ve typed in a form, whether a menu is open.

Examples of state

Short-term and long-term

Some state only lasts while the page is open, like a menu being open. Some is saved, like your basket, so it’s still there tomorrow. Long-term state usually lives in a database.

What it isn’t

It isn’t the app’s code. The code is the same for everyone. State is the bit that’s different for you, right now.

Where the comparison breaks down

A bookmark is one simple thing. A big app juggles thousands of pieces of state at once. Keeping them all in step is one of the hardest parts of building software.

How the words fit together

Your session is part of the app’s state. The frontend shows it. Saved state lives in the database.

Good to know

When an app “forgets” what you typed after you switch away, it lost its state. Good apps save it so you can pick up where you left off.

When you'll hear it

“The state got out of sync.” Two parts of the app disagree about what's going on, so things look wrong.

“It doesn't keep state.” The app forgets everything between visits.

“Reset the state.” Clear everything the app is remembering and start fresh.

Say it in a meeting

“If someone's phone dies halfway through a form, do they have to start again?”