useDocuments
The useDocuments hook is used for loading and displaying a list of the current users documents.
info
Please note that this hook maintains a global state. All instances of this hook will return the same array of documents. This means that if you call loadAll
, the loaded documents will be populated across all instances of the hook.
useDocuments(options)
options
(object) Options for the hook. Optionaloptions.sortBy
('createdAt' | 'updatedAt' | 'unreadCount') How to sort the documents. Defaults to 'updatedAt'options.initialLoad
(number | 'all') How many documents to load when the the hook is first mounted. Pass "all" to load all the documents. If not provided, no documents will be loaded until a loader function is manually called.
Returns
Returns an object with the following properties:
loadMore
((count: number) => Promise<void>) A function that can be called to load more documents. Accepts a number as as parameter which determines how many more documents to load.loadAll
(() => Promise<void>) A function that can be called to load all a users documentsloading
(boolean) A boolean representing if documents are currently being loaded or notdocuments
(Document[]) An array of loaded documents