Cloud API Overview > @adpt/cloud > useConnectTo
useConnectTo() function
Hook that will build an Environment object from components that comply with ConnectToInstance
Signature:
export declare function useConnectTo(connectTo: Handle | Handle[], xform?: (e: Environment) => Environment): Environment | undefined;
Parameters
Parameter | Type | Description |
---|---|---|
connectTo | Handle | Handle[] | A handle or array of handles that point to components that implement ConnectToInstance |
xform | (e: Environment ) => Environment | A method that can transform the provided environment before it is returned |
Returns:
Environment
| undefined
Merged Environment with variables provided by connectTo
components, or undefined
Remarks
Note that this is a hook, and so on first run this will return undefined. After a full build, a state update will trigger a rebuild, at which point the returned Environment will begin to be populated with the variables as the various components are ready to provide them. However, it can take multiple turns of the build-deploy loop to get all the variables.
Moreover, just because a component returns connection information in a variable does not mean it is ready to accept traffic at that time. Components that use this hook to get connection information for other services must be prepared for those services to be temporarily unavailable.
See renameEnvVars() as a function that is useful as an xform
argument.