@instroc/functions
v2.0.0
Published
Serverless function hooks for Instroc Cloud: useFunction and useFunctions
Readme
@instroc/functions
Call your Instroc app's server functions from React. useFunction(name) gives you an invoke call with its own loading and error state; useFunctions() lists the functions the app has. The signed-in user's session travels with every call.
Install
Apps built on Instroc already have it. Instroc pins the version for you; you do not install this by hand. Outside an Instroc app, the package installs like any other:
npm install @instroc/functionsQuick start
import { useFunction } from "@instroc/functions";
export function SendInvoiceButton({ orderId }: { orderId: string }) {
const { invoke, loading, error } = useFunction("send-invoice");
const send = async () => {
const result = await invoke({ orderId });
if (result.success) alert("Invoice sent");
};
return (
<>
<button onClick={send} disabled={loading}>
Send invoice
</button>
{error && <p>{error}</p>}
</>
);
}Versioning
This package follows semantic versioning: a patch release fixes a bug without changing the API, a minor release only adds (new exports, new optional parameters), and anything that removes an export or changes its meaning, shape, default or observable behaviour waits for the next major release. An export on its way out is marked @deprecated with its replacement named, keeps working for at least one minor release and at least 90 days after the changelog announces it, and warns once per page load in development builds. It is removed only in the next major release.
Links
- Documentation: https://docs.instroc.com
- Changelog: CHANGELOG.md, also shipped inside the package at
node_modules/@instroc/functions/CHANGELOG.md
