@softr/sdk
Version:
The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.
30 lines (28 loc) • 864 B
JavaScript
import { useState } from "react";
//#region src/core/use-overrides.ts
/**
* The edits a page has saved that its loader has not re-run for, keyed by record id: what a drawer or
* an inline control wrote, merged over the loader's rows until a fresh read replaces them.
*
* `onSaved` is the shape a drawer's `onSaved` callback takes: it fires before the write, and again
* with the old value if the write fails, so the row moves at once and moves back on failure.
*/
function useOverrides() {
const [pending, setPending] = useState({});
return {
of: (recordId) => pending[recordId],
onSaved: (recordId, patch) => setPending((current) => ({
...current,
[recordId]: {
...current[recordId],
...patch
}
})),
clear: (recordId) => setPending((current) => ({
...current,
[recordId]: void 0
}))
};
}
//#endregion
export { useOverrides };