Menu

Typed Verification Timelines for React Forms
📰

Typed Verification Timelines for React Forms

DEV Community: typescript·ryanlee·2 days ago
#XB3bKEyF
#devtotypescript#devto#dev#kind#state
Reading 0:00
15s threshold

Email verification looks like a small form feature: collect an address, send a code, and show a success message. In a real product, it is a timeline with several actors: the browser, the API, the mail provider, a user who may open two tabs, and a timer that eventually expires.

When those actors disagree, a React component often falls back to a handful of booleans:

const [ loading , setLoading ] = useState ( false ) const [ verified , setVerified ] = useState ( false ) const [ error , setError ] = useState < string | null > ( null )

Enter fullscreen mode

Exit fullscreen mode

This works for the happy path. It gets confusing when a resend request finishes after an old verification request, or when a user returns to a tab after the code has expired. A typed timeline makes the UI easier to reason about and gives tests something more useful than a screenshot to assert.

Why a boolean is not enough

loading , verified , and error can all be true at the same time.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.