How to use @use-it/interval - 9 common examples

To help you get started, we’ve selected a few @use-it/interval examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gnosis / conditional-markets-interface / app / src / Root / index.js View on Github external
Header,
    Menu,
    UserWallet,
    ApplyBetaHeader,
    Toasts,
    Footer
  ] = childComponents;

  // Init and set base state
  const [loading, setLoading] = useState("LOADING");
  const [lastError, setLastError] = useState(null);
  const [syncTime, setSyncTime] = useState(moduleLoadTime);
  const triggerSync = useCallback(() => {
    setSyncTime(Date.now());
  });
  useInterval(triggerSync, SYNC_INTERVAL);
  const [toasts, setToasts] = useState([]);

  const [web3, setWeb3] = useState(null);
  const [account, setAccount] = useState(null);
  const [collateral, setCollateral] = useState(null);
  const [markets, setMarkets] = useState(null);
  const [positions, setPositions] = useState(null);

  const lmsrAddress = match.params.lmsrAddress
    ? match.params.lmsrAddress
    : conf.lmsrAddress;

  const init = useCallback(async () => {
    const { networkId } = conf;
    try {
      console.groupCollapsed("Configuration");
github gnosis / conditional-markets-interface / app / src / MarketTable / ScalarMarketTable / ResolutionTime.js View on Github external
const ResolutionDate = ({ date }) => {
  // use for testing many different random dates
  //const [date, setDate] = useState(Date.now())
  const [timeUntil, setTimeUntil] = useState("");

  const updateCountdown = useCallback(() => {
    // use for testing many different random dates
    //setDate(Date.now() + (Math.random() * 100000000))
    setScalarLocale();
    setTimeUntil(fromNow(date));
  });

  useEffect(updateCountdown, []);
  useInterval(updateCountdown, 1000);

  return <span>{timeUntil}</span>;
};
github gnosis / conditional-markets-interface / app / src / Root / index.js View on Github external
(async () => {
        const whitelistStatus = await getWhitelistState(account);
        setWhitelistState(whitelistStatus);

        if (
          whitelistStatus === "WHITELISTED" ||
          whitelistStatus === "BLOCKED"
        ) {
          setWhitelistCheckIntervalTime(null); // stops the refresh
        }
      })();
    } else {
      setWhitelistState("NOT_FOUND");
    }
  }, [account]);
  useInterval(updateWhitelist, whitelistIntervalTime);

  useEffect(() => {
    updateWhitelist();
  }, [account]);

  const asWrappedTransaction = useCallback(
    (wrappedTransactionType, transactionFn) => {
      return async function wrappedAction() {
        if (ongoingTransactionType != null) {
          throw new Error(
            `Attempted to ${wrappedTransactionType} while transaction to ${ongoingTransactionType} is ongoing`
          );
        }

        if (whitelistEnabled && whitelistState !== "WHITELISTED") {
          openModal("applyBeta", { whitelistState });
github open-rpc / playground / src / App.tsx View on Github external
const defaultExample = examples.find((e) => e.name === "petstore");
    if (!defaultValue && !searchUrl && defaultExample) {
      setSearchUrl(defaultExample.url);
    }
  // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [defaultValue]);

  useEffect(() => {
    setReactJsonOptions({
      ...reactJsonOptions,
      theme: UISchema.appBar["ui:darkMode"] ? "summerfruit" : "summerfruit:inverted",
    });
  // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [UISchema.appBar["ui:darkMode"]]);

  useInterval(() => {
    const modelUriString = "inmemory://openrpc-playground.json";
    const modelUri = monaco.Uri.parse(modelUriString);
    const mk = monaco.editor.getModelMarkers({
      resource: modelUri,
    });
    setMarkers(mk);
  }, 5000);

  useEffect(() => {
    if (results && editor) {
      editor.setValue(results);
    }
    if (results) {
      setParsedSchema(results);
    }
  // eslint-disable-next-line react-hooks/exhaustive-deps
github elastic / kibana / x-pack / legacy / plugins / fleet / public / pages / agent_list / index.tsx View on Github external
// Load initial list of policies
  useEffect(() =&gt; {
    fetchPolicies();
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [showInactive]);

  // Update agents if pagination, query, or policy filter state changes
  useEffect(() =&gt; {
    fetchAgents();
    setAreAllAgentsSelected(false);
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [pagination, search, showInactive, selectedPolicies]);

  // Poll for agents on interval
  useInterval(() =&gt; {
    if (new Date().getTime() - lastPolledAgentsMs &gt;= AGENT_POLLING_INTERVAL) {
      fetchAgents();
    }
  }, AGENT_POLLING_INTERVAL);

  // Some agents retrieved, set up table props
  const columns = [
    {
      field: 'local_metadata.host',
      name: i18n.translate('xpack.fleet.agentList.hostColumnTitle', {
        defaultMessage: 'Host',
      }),
      footer: () =&gt; {
        if (selectedAgents.length === agents.length &amp;&amp; totalAgents &gt; selectedAgents.length) {
          return areAllAgentsSelected ? (
github elastic / kibana / x-pack / legacy / plugins / fleet / public / pages / agent_details / index.tsx View on Github external
export const AgentDetailsPage: React.FC = ({
  match: {
    params: { agentId },
  },
}) =&gt; {
  const [lastPolledAgentsMs, setLastPolledAgentsMs] = useState(0);
  const { agent, isLoading, error, refreshAgent } = useGetAgent(agentId);

  // Poll for agents on interval
  useInterval(() =&gt; {
    if (new Date().getTime() - lastPolledAgentsMs &gt;= AGENT_POLLING_INTERVAL) {
      setLastPolledAgentsMs(new Date().getTime());
      refreshAgent();
    }
  }, AGENT_POLLING_INTERVAL);

  if (isLoading) {
    return ;
  }

  if (error) {
    return (
github contentful / extensions / marketplace / optimizely / src / EditorPage / subcomponents / variation-item.js View on Github external
...entry,
          meta: getAdditionalEntryInformation(entry, allContentTypes, sdk.locales.default)
        };
        actions.setEntry(id, data);
        return entry;
      })
      .catch(() => {
        setError(true);
      });
  }, [actions, allContentTypes, id, sdk.locales.default, sdk.space]);

  useEffect(() => {
    fetchEntry();
  }, [fetchEntry]);

  useInterval(() => {
    fetchEntry();
  }, 3000);

  return {
    entry,
    loading: !entry,
    error
  };
}
github mathdroid / react-moon-toggle / src / index.js View on Github external
}
  };

  const onClick = () =&gt; {
    setDark(!dark);
    setSpeed(interval);
  };

  const onMouseEnter = () =&gt; {
    setHovered(true);
  };
  const onMouseLeave = () =&gt; {
    setHovered(false);
  };

  useInterval(incrementPhase, speed);

  return (
    <button type="button">
      {hovered &amp;&amp; peekOnHover
        ? phases[getNextPhase(phaseIndex)]
        : phases[phaseIndex]}
    </button>
  );
};
github contentful / extensions / marketplace / optimizely / src / EditorPage / index.js View on Github external
*/
  useEffect(() => {
    fetchInitialData(props.sdk, props.client)
      .then(data => {
        actions.setInitialData(data);
        return data;
      })
      .catch(() => {
        actions.setError('Unable to load initial data');
      });
  }, [actions, props.client, props.sdk]);

  /**
   * Pulling current experiment every 5s to get new status and variations
   */
  useInterval(() => {
    if (state.experimentId) {
      props.client
        .getExperiment(state.experimentId)
        .then(experiment => {
          actions.updateExperiment(state.experimentId, experiment);
          return experiment;
        })
        .catch(() => {});
    }
  }, 5000);

  /*
   * Poll to see if we need to show the reauth flow preemptively
   */
  useInterval(() => {
    setShowAuth(isCloseToExpiration(props.expires));

@use-it/interval

A custom React Hook that provides a declarative useInterval.

MIT
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis

Popular @use-it/interval functions