-
Notifications
You must be signed in to change notification settings - Fork 410
/
Copy pathRemoteConfig.tsx
39 lines (34 loc) · 1.27 KB
/
RemoteConfig.tsx
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
import { fetchAndActivate, getRemoteConfig } from 'firebase/remote-config';
import * as React from 'react';
import { RemoteConfigProvider, useRemoteConfigString, useInitRemoteConfig, SuspenseWithPerf } from 'reactfire';
import { CardSection } from '../display/Card';
import { LoadingSpinner } from '../display/LoadingSpinner';
export const RcString = ({ messageKey }) => {
const { data: messageValue } = useRemoteConfigString(messageKey);
return (
<CardSection title="Retrieve string 'message'">
<span>{messageValue}</span>
</CardSection>
);
};
const RemoteConfigWrapper = ({ children }) => {
const { data: remoteConfigInstance } = useInitRemoteConfig(async (firebaseApp) => {
const remoteConfig = getRemoteConfig(firebaseApp);
remoteConfig.settings = {
minimumFetchIntervalMillis: 10000,
fetchTimeoutMillis: 10000,
};
await fetchAndActivate(remoteConfig);
return remoteConfig;
});
return <RemoteConfigProvider sdk={remoteConfigInstance}>{children}</RemoteConfigProvider>;
};
export const RemoteConfig = () => {
return (
<SuspenseWithPerf traceId={'remote-config-message'} fallback={<LoadingSpinner />}>
<RemoteConfigWrapper>
<RcString messageKey="message" />
</RemoteConfigWrapper>
</SuspenseWithPerf>
);
};