| 1 |
import { useState, useLayoutEffect } from '@wordpress/element' |
| 2 |
import { useGlobalStore } from '@library/state/GlobalState' |
| 3 |
import { useUserStore as user } from '@library/state/User' |
| 4 |
|
| 5 |
export const useTestGroup = (key, options, override) => { |
| 6 |
const [group, setGroup] = useState() |
| 7 |
const ready = useGlobalStore((state) => state.ready) |
| 8 |
|
| 9 |
useLayoutEffect(() => { |
| 10 |
if ( |
| 11 |
override || |
| 12 |
(ready && !group) || |
| 13 |
// Let the devbuild reset this |
| 14 |
window.extendifyData._canRehydrate |
| 15 |
) { |
| 16 |
const testGroup = user.getState().testGroup(key, options) |
| 17 |
setGroup(testGroup) |
| 18 |
} |
| 19 |
}, [key, options, group, ready, override]) |
| 20 |
|
| 21 |
return group |
| 22 |
} |
| 23 |
|