Smart card - Hooks
useSmartLinkEvents
Allows for the dispatch of analytics events for a given URL.
Returns a SmartLinkEvents object which can be used to trigger properly formed smart links events. Currently only supports the insertSmartLink event.
const smartLinkEvents = useSmartLinkEvents();
// trigger a smart link inserted analytics event
smartLinkEvents.insertSmartLink(
url,
'inline',
createAnalyticsEvent
);
useSmartLinkActions
Extracts and returns actions for the given URL. useSmartLinkActions
relies on the smart link context so usages must be wrapped in a SmartLinkProvider
or equivalent.
Actions can be customized using the actionOptions
prop.
By default, Smart Links displays all available actions for the link, based on the view component.
- To disable all card actions, set the
hide
prop totrue
. - To disable specific actions, set the
hide
prop tofalse
, and add the action name to theexclude
array prop.
For further information on specific actions, refer to the card actions.
const actions = useSmartLinkActions({ url, apperance: 'block' });
// render the actions
actions.map(action => (
<button onClick={action.handler}>
{action.text}
</button>
));
useSmartLinkReload
Returns a function that can be used to programatically reload a smart link for a given URL. useSmartLinkReload
relies on the smart link context so usages must be wrapped in a SmartLinkProvider
or equivalent.
const reload = useSmartLinkReload({ url });
// reload the smart link
reload();