Add env variable
This commit is contained in:
parent
72d13a54f3
commit
aee1104a1b
2 changed files with 17 additions and 2 deletions
1
xtablo-expo/.env
Normal file
1
xtablo-expo/.env
Normal file
|
|
@ -0,0 +1 @@
|
|||
EXPO_PUBLIC_STREAM_CHAT_API_KEY="t5vvvddteapa"
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import { useEffect } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ActivityIndicator } from "react-native";
|
||||
import { StreamChat } from "stream-chat";
|
||||
import { Chat, OverlayProvider } from "stream-chat-expo";
|
||||
|
||||
|
|
@ -7,7 +8,11 @@ export default function ChatProvider({
|
|||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const client = StreamChat.getInstance("t5vvvddteapa");
|
||||
const [isReady, setIsReady] = useState(false);
|
||||
|
||||
const client = StreamChat.getInstance(
|
||||
process.env.EXPO_PUBLIC_STREAM_CHAT_API_KEY as string
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const connect = async () => {
|
||||
|
|
@ -18,12 +23,21 @@ export default function ChatProvider({
|
|||
},
|
||||
client.devToken("artslidd")
|
||||
);
|
||||
setIsReady(true);
|
||||
const channel = client.channel("messaging", "hello");
|
||||
await channel.watch();
|
||||
};
|
||||
connect();
|
||||
return () => {
|
||||
client.disconnectUser();
|
||||
setIsReady(false);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (!isReady) {
|
||||
return <ActivityIndicator />;
|
||||
}
|
||||
|
||||
return (
|
||||
<OverlayProvider>
|
||||
<Chat client={client}>{children}</Chat>
|
||||
|
|
|
|||
Loading…
Reference in a new issue