Skip to content

Instantly share code, notes, and snippets.

@jchris
Created January 19, 2025 18:16
Show Gist options
  • Save jchris/21af8921ac750e391f9b0a6cdf7f3214 to your computer and use it in GitHub Desktop.
Save jchris/21af8921ac750e391f9b0a6cdf7f3214 to your computer and use it in GitHub Desktop.
quickstart.js
import { useFireproof } from "use-fireproof";
import { connect } from "@fireproof/cloud";
export default function App() {
const { database, useLiveQuery, useDocument } = useFireproof("my_db");
connect(database, '0192b029-0021-7b91-b49d-c5423607bc7b');
const { docs } = useLiveQuery("_id");
const [newDoc, setNewDoc, saveNewDoc] = useDocument({ input: "" });
const handleSubmit = async (e) => {
e.preventDefault();
if (newDoc.input) {
await saveNewDoc();
setNewDoc(); // Reset for new entry
}
};
return (
<div>
<form onSubmit={handleSubmit}>
<input
value={newDoc.input}
onChange={(e) => setNewDoc({ input: e.target.value })}
/>
<button>Add</button>
</form>
<ul>
{docs.map((doc) => (
<li key={doc._id}>{JSON.stringify(doc)}</li>
))}
</ul>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment