0.2.0 • Published 4 months ago

serfu v0.2.0

Weekly downloads
-
License
Unlicense
Repository
-
Last release
4 months ago

Serfu

A library of tiny server-side utilities for SolidStart.

Installation

Run: pnpm install -D serfu

Depending on your project structure, you might have to add serfu to ssr.noExternal in app.config.ts:

export default defineConfig({
  vite: {
    ssr: {
      noExternal: ["serfu"],
    },
  },
});

Utilities

useServerRef

You need local memory in your server functions that is stable across the ssr and server-functions Vinxi routers? useServerRef can be used inside server functions to create and access local memory. This follows similar rules like React Hooks:

  • You can call it multiple times, every call returns a different memory location
  • You should not change the order of the calls at runtime
  • You should not call useServerRef in a condition

Usage

import { useServerRef } from "serfu";

const count = async () => {
  "use server"
  const value = useServerRef(0);
  value.current++;
  return value.current;
};

Use Cases

  • ✅ Store local, unnamed state related to a server function
  • ✅ Memoize expensive server function logic
  • ✅ Cache server function results
  • ⛔️ Store global, named state, that can be accessed from multiple places on the server
0.2.0

4 months ago

0.1.1

7 months ago

0.1.0

11 months ago

0.0.2

1 year ago

0.0.1

1 year ago