@iehr/react-hooks
TypeScript icon, indicating that this package has built-in type declarations

3.1.3 • Public • Published

iEHR React Hooks Library

The iEHR React Hooks Library provides non-UI React features for your application.

Most users will want the full iEHR React Component Library, @iehr/react. However, that library has peer dependencies on Mantine, which may not be desired.

Key Features

  • useIEHR - handles shared global instance of IEHRClient
  • useResource - reads a resource by ID or reference with intelligent caching
  • useSearch - performs a FHIR search with intelligent state management

Installation

Add as a dependency:

npm install @iehr/react-hooks

Note the following peer dependencies:

Setup

import { IEHRClient } from '@iehr/core';
import { IEHRProvider } from '@iehr/react';

const iehr = new IEHRClient();

export function App() {
  return (
    <IEHRProvider iehr={iehr}>
      <MyPage1 />
      <MyPage2 />
      <Etc />
    </IEHRProvider>
  );
}

For more details on how to setup IEHRClient, refer to the docs for iehr.

useIEHR

import { useIEHR } from '@iehr/react-hooks';

export function MyComponent() {
  const iehr = useIEHR();
  return <div>{JSON.stringify(iehr.getProfile())}</div>;
}

useIEHRContext

useIEHRContext can be used to access the IEHRContext provided by the IEHRProvider directly. The IEHRContext has the following interface:

interface IEHRContext {
  iehr: IEHRClient;
  navigate: IEHRNavigateFunction;
  profile?: ProfileResource;
  loading: boolean;
}

Using loading to know when IEHRClient initialization is done

You can use the loading property from useIEHRContext() to know when IEHRClient has finished initialization successfully. loading is updated asynchronously so it will usually start as false and change to true once the client has finished its initialization.

function MyComponent(): JSX.Element {
  const { loading } = useIEHRContext();
  return loading ? (
    <Spinner />
  ) : (
    <div>Loaded!</div>
  );
}

About iEHR

iEHR is a healthcare platform that helps you quickly develop high-quality compliant applications. iEHR includes a FHIR server, React component library, and developer app.

License

Apache 2.0. Copyright © iEHR 2023

Package Sidebar

Install

npm i @iehr/react-hooks

Weekly Downloads

79

Version

3.1.3

License

Apache-2.0

Unpacked Size

62.2 kB

Total Files

10

Last publish

Collaborators

  • hamidrj