A React hook for managing multiple async operations with independent pending states (multi-useTransition).
npm install use-operationsisPending states.
bash
npm install use-operations
import React from "react";
import { useOperations } from "use-operations";
enum Op {
Save,
Delete,
Sync,
}
export default function App() {
const ops = useOperations([Op.Save, Op.Delete, Op.Sync]);
const handleSave = () =>
ops[Op.Save].run(async () => {
await new Promise((r) => setTimeout(r, 1000));
console.log("Saved!");
});
const handleDelete = () =>
ops[Op.Delete].run(async () => {
await new Promise((r) => setTimeout(r, 1500));
console.log("Deleted!");
});
return (
);
}
``