Skip to content

Commit 5e93036

Browse files
authored
keep track of isStaff in state (#55227)
1 parent 4a9a139 commit 5e93036

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/events/components/experiments/useShouldShowExperiment.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ export function useShouldShowExperiment(experimentKey: ExperimentNames | { key:
1313
const [showExperiment, setShowExperiment] = useState(false)
1414
const router = useRouter()
1515
const mainContext = useMainContext()
16+
const [isStaff, setIsStaff] = useState<boolean>(false)
17+
18+
// Fetch `isStaff` one time on mount so we can know if the other useEffect needs to be re-run
19+
useEffect(() => {
20+
let cancelled = false
21+
async function checkStaff() {
22+
const staffValue = await getIsStaff()
23+
if (!cancelled) setIsStaff(staffValue)
24+
}
25+
checkStaff()
26+
return () => {
27+
cancelled = true
28+
}
29+
}, [])
1630

1731
useEffect(() => {
1832
const updateShouldShow = async () => {
@@ -36,7 +50,7 @@ export function useShouldShowExperiment(experimentKey: ExperimentNames | { key:
3650
return () => {
3751
window.removeEventListener('controlGroupOverrideChanged', updateShouldShow)
3852
}
39-
}, [experimentKey, router.locale, mainContext.currentVersion, router.query])
53+
}, [experimentKey, router.locale, mainContext.currentVersion, router.query, isStaff])
4054

4155
return showExperiment
4256
}

0 commit comments

Comments
 (0)