initial
This commit is contained in:
22
web/lib/ab.ts
Normal file
22
web/lib/ab.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
'use client';
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
export const useVariant = () => {
|
||||
const [variant, setVariant] = useState<string | null>(null);
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
const u = new URL(window.location.href);
|
||||
setVariant(u.searchParams.get('ab') ?? 'control');
|
||||
}, []);
|
||||
|
||||
return { variant: variant || 'control', mounted };
|
||||
};
|
||||
|
||||
// Legacy function for backward compatibility
|
||||
export const variant = () => {
|
||||
if (typeof window === 'undefined') return 'control';
|
||||
const u = new URL(window.location.href);
|
||||
return u.searchParams.get('ab') ?? 'control';
|
||||
};
|
||||
Reference in New Issue
Block a user