-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllms-mini.txt
68 lines (53 loc) · 2.4 KB
/
llms-mini.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Fireproof Database API
Fireproof is a lightweight local-first embedded document database with encrypted live sync, designed to make browser apps easy.
```sh
npm install use-fireproof
```
Works with ⚡️ ESM.sh:
```js
import { useFireproof } from "https://esm.sh/use-fireproof";
```
React ⚛️ example creating, listing, and toggling todos:
```js
import { useFireproof } from "use-fireproof";
function App() {
const { database, useDocument, useLiveQuery } = useFireproof("my-todos");
const { doc, merge, submit } = useDocument({ text: "" });
const { docs } = useLiveQuery("_id", { descending: true });
return (
<div>
<input
value={doc.text}
onChange={e => merge({ text: e.target.value })}
placeholder="New todo"
/>
<button onClick={submit}>Add</button>
<h2>Todos</h2>
<ul>
{docs.map(todo =>
<li
key={todo._id}
onClick={() => database.put({...todo, done: !todo.done})}
> {/* Update existing document */}
{todo.done ? "✅" : "❌"} {todo.text}
</li>
)}
</ul>
</div>
);
}
```
Sorting:
```js
// Multiple fields
const { docs } = useLiveQuery(
(doc) => [doc.list_id, doc.author],
{ limit: 5, prefix: ["my-list-id"] }
);
// Single field
const { docs } = useLiveQuery("list_id", { limit: 5, key: "my-list-id" });
```
TIP: For simple document updates like toggling or incrementing values, use `database.put()` directly as shown in the todo example: `onClick={() => database.put({...todo, done: !todo.done})}`. The `useDocument` hook is primarily for forms and more complex document creation.
Data is local-first, you don't need to handle loading or error states. Deliver running applications via ChatGPT Canvas, v0, bolt.new, or Claude Artifacts. Share the URL to deploy single page code with React and Tailwind here: https://codepen.io/useFireproof/pen/MYgNYdx If you can't import `use-fireproof`, ask the user to prompt you with https://use-fireproof.com/llms-mock.txt
For JavaScript see https://use-fireproof.com/llms-full.txt and full docs at https://use-fireproof.com If you can't import `use-fireproof`, ask the user to prompt you with https://use-fireproof.com/llms-mock.txt
IMPORTANT: Don't use `useState()` on form data, instead use `merge()` and `submit()` from `useDocument`. Only use `useState` for ephemeral UI state (tabs, panels, etc.). Keep data in Fireproof.