React bindings for the Abortor core package. This library makes it easier to manage async lifecycles in React components using the Scope
abstraction from @abortor/core
.
# install peer deps (React 18+)
pnpm add react react-dom
# install abortor core & react adapter
pnpm add @abortor/core @abortor/react
import { useScope } from "@abortor/react";
function UserProfile() {
const scope = useScope();
React.useEffect(() => {
const controller = new AbortController();
scope
.fetch("/api/user", { signal: controller.signal })
.then((res) => res.json())
.then((data) => console.log(data))
.catch((err) => {
if (err.name !== "AbortError") {
console.error(err);
}
});
return () => controller.abort();
}, [scope]);
return <div>User profile loading...</div>;
}
function Dashboard() {
const scope = useScope();
React.useEffect(() => {
scope
.all([scope.fetch("/api/stats"), scope.fetch("/api/notifications")])
.then(([stats, notifications]) => {
console.log(stats, notifications);
});
}, [scope]);
return <div>Loading dashboard...</div>;
}
All React hooks are thin adapters over the Core Scope API:
useScope()
→ returns a Scope
bound to the component lifecycle.For full details on Scope
, see @abortor/core.
>=18
Ensure both are installed in your project.