Function: useClassDocs()
function useClassDocs(
stack,
className,
query): object;
Defined in: react/src/hooks/class.ts:318
Hook to retrieve documents (cards) of a specific class. Maintains a real-time list of documents matching the query.
Parameters
| Parameter | Type | Description |
|---|---|---|
stack | string | The name of the stack. |
className | string | The class name to fetch documents for. |
query | { } | Optional Mango selector to filter documents. |
Returns
object
Object containing the list of documents, loading state, and error.
| Name | Type | Defined in |
|---|---|---|
docs | Document[] | react/src/hooks/class.ts:441 |
error | null | react/src/hooks/class.ts:441 |
loading | boolean | react/src/hooks/class.ts:441 |
Example
const UserList = () => {
const { docs, loading } = useClassDocs('my-stack', 'User', {
age: { $gt: 18 }
});
if (loading) return <div>Loading...</div>;
return (
<ul>
{docs.map(doc => <li key={doc._id}>{doc.name}</li>)}
</ul>
);
};