3.1.5 • Published 8 days ago

@medplum/expo-polyfills v3.1.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 days ago

@medplum/expo-polyfills

A module for polyfilling the minimum necessary web APIs for using the Medplum client on React Native

Installation in managed Expo projects

For managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release. If you follow the link and there is no documentation available then this library is not yet usable within managed projects it is likely to be included in an upcoming Expo SDK release.

Installation in bare React Native projects

For bare React Native projects, you must ensure that you have installed and configured the expo package before continuing.

Add the package to your npm dependencies

npm install @medplum/expo-polyfills

Overview

There are currently two major components to this package: 1. The polyfills for getting MedplumClient working without errors in React Native. See: polyfillMedplumWebAPIs 2. The ExpoClientStorage class, which enables MedplumClient to persist what is normally stored in LocalStorage on the web client into a secure storage on a mobile device. Under the hood it uses Expo's SecureStore, but abstracts away the complexity of its asynchronous APIs, since the Storage interface is normally synchronous in nature.

Usage

To get full compatibility with the MedplumClient in React Native, call the polyfillMedplumWebAPIs in the app root and pass in an ExpoClientStorage into your MedplumClient. If you want to wait to load components until after the MedplumClient has initialized, you can conditionally render based on the loading property from the useMedplumContext hook.

import { MedplumClient } from '@medplum/core';
import { MedplumProvider, useMedplumContext } from '@medplum/react-hooks';
import { polyfillMedplumWebAPIs, ExpoClientStorage } from '@medplum/expo-polyfills';

polyfillMedplumWebAPIs();

const medplum = new MedplumClient({ storage: new ExpoClientStorage() });

function Home(): JSX.Element {
  const { loading } = useMedplumContext();
  return loading ? <div>Loading...</div> : <div>Loaded!</div>;
}

function App(): JSX.Element {
  return (
    <MedplumProvider medplum={medplum}>
      <Home />
    </MedplumProvider>
  );
}

Usage with Expo Router

When using MedplumClient with Expo Router, you will likely need to disable the polyfill for window.location; Expo Router provides a polyfill that better interoperates with the package than the Medplum-provided one. See: https://expo.github.io/router/docs/lab/runtime-location#native

To disable the Medplum window.location polyfill, simply pass the following config to polyfillMedplumWebAPIs:

polyfillMedplumWebAPIs({ location: false });
3.1.5

8 days ago

3.1.4

13 days ago

3.1.3

16 days ago

3.1.2

30 days ago

3.1.1

1 month ago

3.1.0

1 month ago

3.0.13

1 month ago

3.0.12

1 month ago

3.0.11

2 months ago

3.0.10

2 months ago

3.0.9

2 months ago

3.0.8

2 months ago

3.0.7

2 months ago

3.0.6

2 months ago

3.0.5

2 months ago

3.0.4

3 months ago

3.0.3

3 months ago

3.0.2

3 months ago

3.0.1

4 months ago

3.0.0

4 months ago

2.2.10

4 months ago

2.2.7

4 months ago

2.2.6

4 months ago

2.2.5

5 months ago

2.2.4

5 months ago

2.2.3

5 months ago

2.2.2

5 months ago

2.2.1

5 months ago

2.2.0

5 months ago

2.1.25

5 months ago

2.1.24

5 months ago

2.1.23

5 months ago

2.1.22

5 months ago

2.1.21

5 months ago

2.1.20

5 months ago

2.1.19

5 months ago

2.1.18

6 months ago

2.1.17

6 months ago

2.1.16

6 months ago

2.1.15

6 months ago

2.1.14

6 months ago

2.1.13

6 months ago

2.1.12

6 months ago

2.1.11

6 months ago