# Fireproof Mock Guide Fireproof is a lightweight embedded document database with encrypted live sync, designed to make browser apps easy. Implementation: ```js import * as React from "react"; const useFireproof = (dbName) => { const [state, setState] = React.useState({ database: null, docs: [] }); React.useEffect(() => { if (!state.database) { setState(s => ({ ...s, database: { put: (doc) => { const docWithId = { ...doc, _id: doc._id || `doc_${Date.now()}_${Math.random()}` }; setState(s => ({ ...s, docs: s.docs.some(d => d._id === docWithId._id) ? s.docs.map(d => d._id === docWithId._id ? docWithId : d) : [...s.docs, docWithId] })); return Promise.resolve({ ok: true, id: docWithId._id }); }, get: (id) => { const doc = state.docs.find(d => d._id === id); return doc ? Promise.resolve(doc) : Promise.reject(new Error(`Document with id ${id} not found`)); }, del: (idOrDoc) => { const id = typeof idOrDoc === 'string' ? idOrDoc : idOrDoc._id; const docExists = state.docs.some(d => d._id === id); if (docExists) { setState(s => ({ ...s, docs: s.docs.filter(d => d._id !== id) })); return Promise.resolve({ ok: true, id }); } else { return Promise.reject(new Error(`Document with id ${id} not found`)); } } } })); } }, []); return { database: state.database, useDocument: (initialDoc = {}) => { const [doc, setDoc] = React.useState(initialDoc); return { doc, merge: (update) => setDoc(current => ({ ...current, ...update })), submit: () => state.database ? state.database.put(doc) : Promise.reject(new Error("Database not initialized")) }; }, useLiveQuery: (field, options = {}) => { const { docs } = state; let filteredDocs = [...docs]; if (typeof field === 'string' && options.key) { filteredDocs = filteredDocs.filter(doc => doc[field] === options.key); } else if (typeof field === 'string' && options.descending !== undefined) { filteredDocs.sort((a, b) => { return options.descending ? (b[field] || '').toString().localeCompare((a[field] || '').toString()) : (a[field] || '').toString().localeCompare((b[field] || '').toString()); }); } else if (typeof field === 'function') { if (options.prefix && Array.isArray(options.prefix)) { filteredDocs = filteredDocs.filter(doc => { const fieldValues = field(doc); return options.prefix.every((prefix, i) => fieldValues[i] && fieldValues[i].toString().startsWith(prefix) ); }); } } if (options.limit && typeof options.limit === 'number') { filteredDocs = filteredDocs.slice(0, options.limit); } return { docs: filteredDocs }; } }; }; ``` React ⚛️ example creating, listing, and toggling todos: ```js function App() { const { database, useDocument, useLiveQuery } = useFireproof("my-todos"); const { doc, merge, submit } = useDocument({ text: "" }); const { docs } = useLiveQuery("_id", { descending: true }); return (