Skip to main content

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

ParameterTypeDescription
stackstringThe name of the stack.
classNamestringThe 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.

NameTypeDefined in
docsDocument[]react/src/hooks/class.ts:441
errornullreact/src/hooks/class.ts:441
loadingbooleanreact/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>
);
};