-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathformbricks.tsx
More file actions
49 lines (42 loc) · 1.42 KB
/
formbricks.tsx
File metadata and controls
49 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { SurveyWebView } from "@/components/survey-web-view";
import { Logger } from "@/lib/common/logger";
import { setup } from "@/lib/common/setup";
import { SurveyStore } from "@/lib/survey/store";
import React, { useCallback, useEffect, useSyncExternalStore } from "react";
import { View } from "react-native";
interface FormbricksProps {
appUrl: string;
environmentId: string;
}
const surveyStore = SurveyStore.getInstance();
const logger = Logger.getInstance();
export function Formbricks({ appUrl, environmentId }: FormbricksProps): React.JSX.Element | null {
// initializes sdk
useEffect(() => {
const setupFormbricks = async (): Promise<void> => {
try {
await setup({
environmentId,
appUrl,
});
} catch {
logger.debug("Initialization failed");
}
};
setupFormbricks().catch(() => {
logger.debug("Initialization error");
});
}, [environmentId, appUrl]);
const subscribe = useCallback((callback: () => void) => {
const unsubscribe = surveyStore.subscribe(callback);
return unsubscribe;
}, []);
const getSnapshot = useCallback(() => surveyStore.getSurvey(), []);
const survey = useSyncExternalStore(subscribe, getSnapshot);
// Wrap in View with pointerEvents="box-none" to fix Android touch event handling.
return survey ? (
<View pointerEvents="box-none">
<SurveyWebView survey={survey} />
</View>
) : null;
}