Skip to main content
Back to React

useFlowVariables()

The useFlowVariables hook loads the variables a flow declares for an organization unit, the values the unit has set, and what the unit may do with each variable. It also saves the unit's overrides. It is the data layer behind <FlowVariablesForm />, so use it to build the form with your own UI.

Usage​

src/FlowVariables.jsx
jsx
import { useFlowVariables, BaseFlowVariables } from '@thunderid/react'

function FlowVariables({ flowId, ouId }) {
const { connections, definitions, overlay, overrides, isLoaded, isSaving, save, saveError, error } =
useFlowVariables({ flowId, ouId })

if (!isLoaded && !error) return <p>Loading...</p>
if (error) return <p>Could not load the variables.</p>

return (
<BaseFlowVariables
variables={definitions}
connections={connections}
overlay={overlay}
initialValues={overrides}
isSubmitting={isSaving}
error={saveError?.message ?? null}
onSubmit={(values, changed) => save(changed)}
/>
)
}
note

The hook must be used inside a component rendered within ThunderIDProvider. The access token of the signed-in user needs the permissions the server requires to read and update the flow's variables.

The hook keeps the data it loaded while it fetches for a new flowId or ouId, so the previous values can stay on screen and be saved against the new flow. Render the component that calls the hook with a key of both identifiers, for example <FlowVariables key={ouId + ':' + flowId} flowId={flowId} ouId={ouId} />, so it starts clean when either changes.

Options​

OptionTypeDefaultDescription
flowIdstring | undefinedIdentifier of the flow. No request is sent until it is set.
ouIdstring | undefinedThe organization unit whose overrides are read and saved. No request is sent until it is set.
enabledbooleantrueSet to false to skip fetching.
fetcher(url: string, config: RequestInit) => Promise<Response>See Fetcher ResolutionTransport for this hook only.
onSaved(values: FlowVariableValues) => voidCalled with the saved overrides after a successful save.

Return Values​

PropertyTypeDescription
definitionsFlowVariableDefinition[]The variables the flow declares for the organization unit.
overridesFlowVariableValuesThe values the unit has set. A variable the unit has not set is absent, and its default applies.
overlayResolvedOverlay | undefinedWhat the unit may do with each variable: set its own value, or only see the owner's.
connectionsConnectionInstance[]The connections a CONNECTION_SELECT variable can take: the ones the unit owns and the ones shared into it. Empty until loaded, and when no variable needs them.
flowManagedFlowDefinition | undefinedThe flow as the unit sees it.
isLoadedbooleantrue once the variables, the unit's values, and its rules have all arrived. Build the form after this, because a form built earlier is reset when the values land.
isLoadingbooleantrue while any request is in flight.
isSavingbooleantrue while a save is in flight.
errorError | nullWhy the variables could not be loaded.
save(values: FlowVariableValues) => Promise<FlowVariables | undefined>Replaces the unit's overrides. A variable left out returns to its default. Never rejects, so read saveError to handle a failure.
saveErrorError | nullWhy the last save failed.

A successful save refetches the unit's values. The hook requests the connections only when the flow declares a CONNECTION_SELECT variable.

Explore with AI

ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© Copyright Linux Foundation Europe.For web site terms of use, trademark policy and other project policies please see https://linuxfoundation.eu/en/policies.