useMemo so they are not recreated on every render), wrap your component tree with the Form filling Provider, and render FormFilling when the clinician should fill forms.
Use this approach if you are building with React and want to manage Form filling through components and hooks instead of imperative calls.
Let’s get started!
Prerequisites
Before you begin, you must have the following requirements met:- Packages: Install
@suki-sdk/reactand@suki-sdk/core(Web SDKv3.2.0or later). - Partner credentials: Obtain
partnerIdandpartnerTokenfrom Suki after Partner onboarding. - Template IDs:
template_idUUIDs from your Suki support team forform_template_ids. - Encounter ID: Pass your encounter ID as
correlation_id. Refer to Configuration for more details. - Browser and layout: Your app runs in a browser over HTTPS, with microphone access and enough layout for the Form filling UI.
Install the packages
Add the following packages to the same project you load in the browser:Step 1: Style the container
React renders the hosted UI inside.suki-form-filling. Give that container explicit height, or the iframe looks blank.
CSS
Step 2: Create auth manager
Now you need to create the Auth Manager for your application. To create the Auth Manager, you must have thepartnerId and partnerToken credentials from Suki.
Refer to Partner onboarding guide to learn how to get these credentials.
In React you usually create the auth manager inside the same useMemo as the Form filling client (see Step 3), so both exist once per page or shell. The snippet below shows only the auth piece for clarity.
Code example for creating auth manager
JavaScript
Step 3: Create Form filling client
After you have created the auth manager, you can create the Form filling client for your application. The Form filling Client is the object the React components use under the hood. Create one Form filling client and reuse it for the whole tree underFormFillingProvider. Use useMemo with an empty dependency array so you do not run new FormFillingClient(...) on every render.
Code example for creating Form filling client in React
React
Step 4: Wrap with FormFillingProvider
Pass theclient from Step 3 into FormFillingProvider. Every component that renders <FormFilling> must be a child of that provider.
Code example for wrapping with FormFillingProvider
React
FormFillingProvider at app root or only around the screen that needs Form filling.
Step 5: Render FormFilling
Render<FormFilling> only while Form filling should be open (for example when the clinician clicked “Fill Forms with Suki”). When <FormFilling> unmounts, the SDK tears down the hosted UI for you.
Pass form_template_ids, onSubmit, and any optional props you need. Refer to Configuration guide for more details on the available options and how to use them.
Code example for rendering FormFilling in React
React
onSubmit is required. It runs when structured JSON is ready after processing, not when the clinician taps submit in the hosted UI.Callbacks
Props such asonReady, onSubmit, and onCancel mirror the JavaScript start() callbacks. onBackgroundSubmit is React-only (results for a superseded session while the iframe is still open). You can also listen with client.on() for handlers that stay active across many sessions:
React
FormFillingResult shape and Events for every event and payload.
useFormFilling hook
InsideFormFillingProvider, use useFormFilling() to read session state and errors in sibling components:
React
Starting another session
Use the sameclient and FormFillingProvider. Mount <FormFilling> again (for example set isFormOpen back to true). You do not need a new FormFillingClient. Mount only one <FormFilling> at a time per client.
Unmounting
When<FormFilling> unmounts, the SDK automatically tears down the hosted UI. You do not need to call stop() yourself for normal React flows.
Complete code example
Below is a complete code example in React withFormFillingProvider, a launch button, and one Form filling session.
React
onSubmit returns structured_data, and only one <FormFilling> is mounted at a time for that client.