Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-ab-test-hooks",
"version": "1.0.4",
"version": "1.0.5",
"description": "A fast and lightweight AB-Testing library for React and Next.js based on hooks and functional components",
"author": "NiklasMencke",
"license": "MIT",
Expand Down
9 changes: 8 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const getWeightedRandomInt = (spec: any): number => {
table.push(i);
}
}
console.log(table, Number(table[Math.floor(Math.random() * table.length)]))
return Number(table[Math.floor(Math.random() * table.length)]);
};

Expand Down Expand Up @@ -109,7 +110,13 @@ const useVariant = ({
error: string | null;
} => {
const [resultIndex, setResultIndex] = useState<number>(
cacheResult ? (Number(getVariantFromStorage(id)) ? Number(getVariantFromStorage(id)) : -1) : -1,
() => {
if (cacheResult) {
const savedVariant = getVariantFromStorage(id);
if (typeof savedVariant === "string") return Number(getVariantFromStorage(id));
}
return -1;
}
);
const [error, setError] = useState<string | null>(null);

Expand Down