@unifygtm/intent-react
Version:
Library for using the Unify Intent JS Client in a React app.
24 lines (18 loc) • 542 B
text/typescript
import { useContext } from 'react';
import { UnifyIntentContext } from './UnifyIntentProvider';
/**
* This hook returns the current `UnifyIntentClient`. It should only be
* used from within a `UnifyIntentProvider` component.
*
* @returns the current Unify Intent Client
*/
function useUnifyIntent() {
const { client } = useContext(UnifyIntentContext);
if (client === null) {
throw new Error(
'useUnifyIntent can only be used within a UnifyIntentProvider.',
);
}
return client;
}
export default useUnifyIntent;