From aad8c080eda81ad96875c817420d719a8c80874f Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 9 Mar 2024 00:29:31 +0000 Subject: [PATCH] Poll Statsig for config changes (#3158) --- src/lib/statsig/statsig.tsx | 12 ++++++++++++ src/lib/statsig/statsig.web.tsx | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/lib/statsig/statsig.tsx b/src/lib/statsig/statsig.tsx index 43822dda..6d9ebeb0 100644 --- a/src/lib/statsig/statsig.tsx +++ b/src/lib/statsig/statsig.tsx @@ -48,6 +48,18 @@ export function Provider({children}: {children: React.ReactNode}) { () => toStatsigUser(currentAccount?.did), [currentAccount?.did], ) + + React.useEffect(() => { + function refresh() { + // Intentionally refetching the config using the JS SDK rather than React SDK + // so that the new config is stored in cache but isn't used during this session. + // It will kick in for the next reload. + Statsig.updateUser(currentStatsigUser) + } + const id = setInterval(refresh, 3 * 60e3 /* 3 min */) + return () => clearInterval(id) + }, [currentStatsigUser]) + return ( toStatsigUser(currentAccount?.did), [currentAccount?.did], ) + + React.useEffect(() => { + function refresh() { + // Intentionally refetching the config using the JS SDK rather than React SDK + // so that the new config is stored in cache but isn't used during this session. + // It will kick in for the next reload. + Statsig.updateUser(currentStatsigUser) + } + const id = setInterval(refresh, 3 * 60e3 /* 3 min */) + return () => clearInterval(id) + }, [currentStatsigUser]) + return (