UNPKG

@hisptz/react-ui

Version:

A collection of reusable complex DHIS2 react ui components.

40 lines (39 loc) 816 B
import { useState, useEffect } from "react"; const query = { identify: { resource: "identifiableObjects", id: _ref => { let { id } = _ref; return id; } } }; export function useIdentifyObject(engine, id) { const [loading, setLoading] = useState(true); const [error, setError] = useState(false); const [data, setData] = useState(); useEffect(() => { async function fetch() { const data = await engine.query(query, { variables: { id } }); return data === null || data === void 0 ? void 0 : data.identify; } fetch().then(val => { setData(val); setLoading(false); }).catch(err => { setError(err); setLoading(false); }); }, [id]); return { loading, error, data }; }