Skip to content

Commit 16aa2d1

Browse files
authored
Merge pull request #11 from appwrite/fix-SER-265-fix-react-native-onboarding
fix: ssr issues
2 parents 2f319b1 + e0791f7 commit 16aa2d1

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

app/index.tsx

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
View,
88
} from "react-native";
99
import { Header } from "@/components/Header";
10-
import { useMemo, useRef, useState } from "react";
10+
import { useMemo, useRef, useState, useEffect } from "react";
1111
import { Card } from "@/components/Card";
1212
import { fontStyles } from "@/styles/font";
1313
import { IconArrowSmRight } from "@/assets/images/IconArrowSmRight";
@@ -22,6 +22,35 @@ const client = new Client()
2222
.setProject(process.env.EXPO_PUBLIC_APPWRITE_PROJECT_ID ?? "")
2323
.setEndpoint(process.env.EXPO_PUBLIC_APPWRITE_ENDPOINT ?? "");
2424

25+
// prevent ssr issues
26+
function ClientOnlyBottomSheet({ children, ...props }: any) {
27+
const [isClient, setIsClient] = useState(false);
28+
29+
useEffect(() => {
30+
setIsClient(true);
31+
}, []);
32+
33+
if (!isClient) {
34+
return null;
35+
}
36+
37+
return <BottomSheet {...props}>{children}</BottomSheet>;
38+
}
39+
40+
function ClientOnlyGestureHandler({ children }: { children: React.ReactNode }) {
41+
const [isClient, setIsClient] = useState(false);
42+
43+
useEffect(() => {
44+
setIsClient(true);
45+
}, []);
46+
47+
if (!isClient) {
48+
return <>{children}</>;
49+
}
50+
51+
return <GestureHandlerRootView>{children}</GestureHandlerRootView>;
52+
}
53+
2554
export default function HomeScreen() {
2655
const [connectionState, setConnectionState] = useState<
2756
"idle" | "loading" | "success" | "error"
@@ -86,7 +115,7 @@ export default function HomeScreen() {
86115

87116
return (
88117
<View style={{ flex: 1 }}>
89-
<GestureHandlerRootView>
118+
<ClientOnlyGestureHandler>
90119
<ScrollView>
91120
<Header pingFunction={doPing} state={connectionState} />
92121
<View
@@ -126,7 +155,7 @@ export default function HomeScreen() {
126155
</Card>
127156
</View>
128157
</ScrollView>
129-
<BottomSheet
158+
<ClientOnlyBottomSheet
130159
index={0}
131160
snapPoints={snapPoints}
132161
enablePanDownToClose={false}
@@ -141,8 +170,8 @@ export default function HomeScreen() {
141170
logs={logs}
142171
/>
143172
</BottomSheetView>
144-
</BottomSheet>
145-
</GestureHandlerRootView>
173+
</ClientOnlyBottomSheet>
174+
</ClientOnlyGestureHandler>
146175
</View>
147176
);
148177
}
@@ -176,4 +205,4 @@ const styles = StyleSheet.create({
176205
flexDirection: "row",
177206
justifyContent: "flex-start",
178207
},
179-
});
208+
});

0 commit comments

Comments
 (0)