Skip to content

Commit

Permalink
prevent fetching the counter twice
Browse files Browse the repository at this point in the history
  • Loading branch information
tttp committed Sep 15, 2024
1 parent b9bfded commit ed23a83
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/hooks/useCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { useCampaignConfig } from "@hooks/useConfig";
import { atom, useRecoilState } from "recoil";
import dispatch from "@lib/event.js";

let effectRan = false;

const CountState = atom({ key: "actionCount", default: null });
const useInitFromUrl = (actionUrl) => {
const [count, setCount] = useRecoilState(CountState);
Expand Down Expand Up @@ -51,6 +53,8 @@ export default function useCounter(actionPage) {
if (config.component.counter === false) actionPage = null; //disable the counter

useEffect(() => {
if (effectRan) return; //we only fetch the counter once for all components
effectRan = true;
let isCancelled = false;
let c = null;
if (!actionPage || config.component.counter?.disabled) return; // disabling the fetch
Expand Down

0 comments on commit ed23a83

Please sign in to comment.