Make React async predictable. End of chaos.
A deterministic execution layer for handling async logic and errors in React applications.
React applications today have fragmented async behavior:
- scattered
try/catch - inconsistent error handling
- no unified async state model
- race conditions and stale updates
- different patterns across fetch, actions, effects
react-async-boundary solves this by introducing a single execution layer for all async logic in React.
Instead of handling async logic everywhere differently, you run everything through one deterministic system:
run(asyncFunction)That’s it.
- Unified async execution layer
- Standardized error model
- Predictable async state machine
- Cancellation support (AbortController)
- Simple retry mechanism
- React hook-based API
npm install react-async-boundaryor
pnpm add react-async-boundaryimport { useAsync } from "react-async-boundary"
function App() {
const { run, state, error, data } = useAsync()
const handleClick = async () => {
await run(() => fetch("/api/user").then(r => r.json()))
}
return (
<div>
<button onClick={handleClick}>Load</button>
{state.status === "running" && <p>Loading...</p>}
{state.status === "error" && <p>{error.message}</p>}
{state.status === "success" && <pre>{JSON.stringify(data)}</pre>}
</div>
)
}type AsyncState =
| { status: "idle" }
| { status: "running" }
| { status: "success"; data: any }
| { status: "error"; error: any }
| { status: "retrying"; attempt: number }
| { status: "cancelled" }type AsyncError = {
type: "network" | "validation" | "auth" | "runtime" | "unknown"
message: string
retryable: boolean
raw?: unknown
}const { run, state, error, data, reset } = useAsync()await run(() => apiCall(), {
retry: 2
})<AsyncBoundary fallback={ErrorFallback}>
<App />
</AsyncBoundary>- Deterministic async execution
- Unified error handling
- Minimal API surface
- Not React Query replacement
- Not caching library
- Not data layer
MIT