Skip to content

Commit

Permalink
Delay fetching of streams due to rate limiting.
Browse files Browse the repository at this point in the history
  • Loading branch information
vikpe committed May 28, 2024
1 parent edc87ed commit 6cdb495
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Streams.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { Heading } from "@qwhub/Common";
import { useGetStreamsQuery } from "@qwhub/services/hub/hub";
import React, { Fragment } from "react";
import React, { Fragment, useState } from "react";
import { useTimeout } from "usehooks-ts";
import { TwitchButton } from "./Buttons";

function useDelay(delay) {
const [skip, setSkip] = useState(true);
useTimeout(() => {
setSkip(false);
}, delay);
return skip;
}

export function FeaturedStreams() {
const skip = useDelay(1500);
const { data: streams = [] } = useGetStreamsQuery(null, {
pollingInterval: 15500,
skip,
});

return (
Expand All @@ -26,7 +37,8 @@ const FeaturedStream = (props) => {
};

export function AllStreams() {
const { data: streams = [] } = useGetStreamsQuery(null);
const skip = useDelay(1520);
const { data: streams = [] } = useGetStreamsQuery(null, { skip });

return (
<div className="app-links my-8">
Expand Down

0 comments on commit 6cdb495

Please sign in to comment.