Skip to content

Commit 0bbee03

Browse files
author
Edward Marzal
committed
adding hooks
1 parent a43b7b9 commit 0bbee03

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

ui/src/hooks/useAnalytics.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useAppSdk } from './useAppSdk';
2+
3+
const useAnalytics = () => {
4+
const [appSdk] = useAppSdk();
5+
6+
const trackEvent = (event: string, eventData: any = {}) => {
7+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
8+
// @ts-ignore
9+
return appSdk?.pulse(event, eventData);
10+
};
11+
12+
return { trackEvent };
13+
};
14+
15+
export default useAnalytics;

ui/src/hooks/useAppSdk.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* useAppSdk
3+
* @return the appSdk instance after initialization
4+
* This hook is to utilize for appSdk pulse method and its an exception for dev tools app.
5+
*/
6+
import { atom, useAtom } from 'jotai';
7+
import Extension from '@contentstack/app-sdk/dist/src/extension';
8+
9+
export const appSdkRefAtom = atom<Extension | null>(null);
10+
11+
/**
12+
* Getter and setter for appSdk instance.
13+
* To be used during Sdk initialization
14+
*/
15+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
16+
export const useAppSdk = (): [Extension | null, any] => {
17+
return useAtom(appSdkRefAtom);
18+
};

0 commit comments

Comments
 (0)