惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
博客园 - 司徒正美
Last Week in AI
Last Week in AI
爱范儿
爱范儿
罗磊的独立博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
量子位
V
V2EX
博客园 - 叶小钗
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Handling React Dialog Flows with async/await
KANGYEOLCHO · 2026-06-26 · via DEV Community

KANGYEOLCHO

React dialogs often start simple.

You add an isOpen state, then a selected item state, then confirm/cancel callbacks, then another dialog after the first one.

Eventually, a simple flow can become scattered across multiple components.

For example, a user flow like this:

  1. Select a user
  2. Confirm the action
  3. Add the user

often becomes multiple pieces of state:

const [isUserSearchOpen, setIsUserSearchOpen] = useState(false);
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
const [selectedUser, setSelectedUser] = useState<User | null>(null);

This works, but the actual flow is harder to read.

What if dialogs could be handled as async flows?

I wanted the code to read closer to the user flow:

const user = await openAsync(UserSearchDialog);
if (!user) return;

const confirmed = await openAsync(ConfirmDialog, {
  title: `Add ${user.name}?`,
});

if (confirmed) {
  await addUser(user.id);
}

The dialog opens, waits for a result, and the caller continues based on that result.

This is about orchestration, not UI

This is not meant to replace Radix, MUI, Headless UI, shadcn/ui, or custom dialog components.

Those libraries solve the dialog UI problem well.

The idea here is to manage the flow around dialogs:

  • opening dialogs from anywhere under a provider
  • resolving typed result values
  • handling nested dialogs
  • distinguishing completed vs dismissed
  • supporting dismissal reasons
  • guarding close behavior with shouldClose

So the actual dialog UI can still be your own component.

I packaged the pattern

I turned this idea into a small open-source library called react-dialog-flow.

It provides a headless dialog stack, Promise-based openAsync, typed results, nested dialogs, closeTop, closeAll, dismissal reasons, shouldClose, and optional UI primitives.

GitHub: https://github.com/CHOKANGYEOL/react-dialog-flow

npm: https://www.npmjs.com/package/react-dialog-flow

Docs: https://dialog-flow.kangyeol.com/

It is still early, so I am mainly looking for feedback on the API design.

Would you use async/await for dialog flows in React, or would you keep this logic inside app-specific hooks?