Function: useFind()
function useFind(
stack,
query,
sort?,
limit?): object;
Defined in: react/src/hooks/index.ts:178
Hook to find documents in a stack using a Mango selector.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
stack | string | undefined | The name of the stack to query. |
query | { fields?: string[]; selector: { [key: string]: string | number; }; } | undefined | Object containing the selector and optional fields projection. |
query.fields? | string[] | undefined | - |
query.selector? | { [key: string]: string | number; } | undefined | - |
sort? | any | undefined | Optional sort criteria. |
limit? | number | 50 | Maximum number of documents to return (default: 50). |
Returns
object
Object containing the list of documents, loading state, and error.
| Name | Type | Defined in |
|---|---|---|
docs | Document[] | react/src/hooks/index.ts:261 |
error | null | react/src/hooks/index.ts:261 |
loading | boolean | react/src/hooks/index.ts:261 |
Example
const ActiveTasks = () => {
const { docs, loading } = useFind('my-stack', {
selector: {
"~class": "Task",
active: true
},
fields: ['_id', 'title']
});
if (loading) return <div>Loading...</div>;
return (
<ul>
{docs.map(doc => <li key={doc._id}>{doc.title}</li>)}
</ul>
);
};