Skip to main content

useDocument

A hook for asynchronously working with documents.

Parameters

NameTypeOptionalDescription
idReferencestringFalseThe ID reference of the document on format DATA_SOURCE/UUID.Attribute
depthnumberTrueThe maximum depth level of nested objects to resolve
notifybooleanFalseShow a pop-up on failed/successful requests

Returns

A list containing the document, a boolean representing the loading state, a function to update the document, and an Error, if any.

Usage

Code example:

import { useDocument } from '@data-modelling-tool/core'

const {
  document,
  loading,
  updateDocument,
  error,
} = useDocument(dataSourceId, documentId)

if (loading) return <div>Loading...</div>

if (error) {
  console.error(error)
  return <div>Error getting the document</div>
}

<DisplayDocument document={document} />