@j2inn/app-react
Version:
React implementation of the j2inn-app framework
26 lines (25 loc) • 868 B
JavaScript
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
/*
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
*/
import { HFilterBuilder, HRef } from 'haystack-core';
import { useClient } from 'haystack-react';
import { useEffect, useState } from 'react';
/**
* Loads a record and renders a representation of it.
*/
export const RecordInfo = (props) => {
const { target, render } = props;
const client = useClient();
const [record, setRecord] = useState();
useEffect(() => {
if (target) {
client.ops
.read(new HFilterBuilder().equals('id', HRef.make(target)).build())
.then((grid) => {
setRecord(grid.first);
});
}
}, [client, target]);
return target && record ? render(record) : _jsx(_Fragment, {});
};