JSPM

react-router-durable

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q10215F
  • License MIT

A package for using Cloudflare Durable Objects as React Router loaders and actions

Package Exports

  • react-router-durable

Readme

react-router-durable

A package for using Cloudflare's Durable Objects as React Router loaders and actions.

downloads npm version MIT license

Example

// /app/durable-objects.ts
import type { LoaderFunctionArgs } from "react-router";
import { DurableObject } from "cloudflare:workers";

export class SampleDurableObject extends DurableObject {
  async sampleLoader({ request }: LoaderFunctionArgs) {
    return { url: request.url };
  }
}

// /app/routes/home.tsx
import { durableLoader } from "react-router-durable";
import { SampleDurableObject } from "../durable-objects";

// Makes a react-router loader that proxies the load to the SampleDurableObject
export const loader = durableLoader(
  SampleDurableObject,
  (env) => env.sample.sampleLoader,
  "sample" // the name of the DurableObject to use
);

export default function Home() {
  const { url } = useLoaderData<typeof loader>();

  return <h1>url: {url}</h1>;
}

Installation

# NPM
$ npm install --save react-router-durable
# Yarn
$ yarn add react-router-durable
# PNPM
$ pnpm add react-router-durable
# Bun
$ bun add react-router-durable

License

Distributed under the MIT License. See LICENSE for more information.