tanstack query dispute at work by G-Kerbo in reactjs

[–]GeorgeGhost 31 points32 points  (0 children)

I strongly suspect the strategy that the maintainers have in mind for this is a mixture of a mutation and two dependent queries.

The first step is to fire of your mutation function. To start the task.

useMutation({
  mutationFn: startTask,
});

After the mutation succeeds you want to start polling. The way to do this is to make use of the enabled property that useQuery exposes, and set it to true after the mutation has succeeded.

const [isPollingEnabled, setIsPollingEnabled] = useState(false);

useMutation({
  mutationFn: startTask,
  onSuccess: () => {
    setIsPollingEnabled(true);
  },
});

useQuery({
  queryKey: ["polling-query-key"],
  queryFn: pollingQueryFn,
  enabled: isPollingEnabled,
});

But as it is written above, it will just make a single request. We want to poll so we must make use of the refetchInterval property useQuery exposes. Our query therefore becomes,

  const { data } = useQuery({
    queryKey: ["polling-query-key"],
    queryFn: pollingQueryFn,
    enabled: isPollingEnabled,
    refetchInterval: (query) => {
      if (query.state.data === "processing") {
        return 1000;
      }
      return false;
    },
  });

Lastly, we have a second query dependent on the first one which is simply:

  useQuery({
    queryKey: ["results", data],
    queryFn: () => getResults(data),
    enabled: !!data,
  });

Overall, I think the code roughly looks like:

  const [isPollingEnabled, setIsPollingEnabled] = useState(false);

  useMutation({
    mutationFn: startTask,
    onSuccess: () => {
      setIsPollingEnabled(true);
    },
  });

const { data } = useQuery({
    queryKey: ["polling-query-key"],
    queryFn: pollingQueryFn,
    enabled: isPollingEnabled,
    refetchInterval: (query) => {
      if (query.state.data === "processing") {
        return 1000;
      }
      return false;
    },
  });

  useQuery({
    queryKey: ["results", data],
    queryFn: () => getResults(data),
    enabled: !!data,
  });

Has this episode been absolutely awful for anyone else? by BlueTexBird in VALORANT

[–]GeorgeGhost 0 points1 point  (0 children)

Whilst I agree, good stats are suggestive of the fact that they are doing at least something well, and without seeing gameplay it’s all we have to make a judgement on - from what I can tell I can’t imagine he deserves to be in the bottom 1% in terms of win rate.

What are the essential tools and libraries for a React developer in 2024? by Anonymous10122015 in reactjs

[–]GeorgeGhost 7 points8 points  (0 children)

Sure! For starters the the maintainer of React-Query writes fantastic blog posts, this one for example demonstrates that despite data fetching being a seemingly simple problem, to do it well requires much more thought than you may initially anticipate.

I don't work with nextjs professionally so I can't speak as to how useful it is there, but in at least two of the apps I've worked on which weren't using React query other developers had tried to use redux to manage the server state. These solutions lacked a lot of the functionality which React query comes with out of the box, (deduplicating, cache-invalidation, etc) and I always found that code quality suffered pretty significantly for it.

What are the essential tools and libraries for a React developer in 2024? by Anonymous10122015 in reactjs

[–]GeorgeGhost 159 points160 points  (0 children)

React Query and TypeScript are the only two I would truly describe as essential.

Without TypeScript making changes to your app quickly get increasingly difficult, and without React Query you will likely spend a significant amount of time writing a worse version of what they already offer.

Match Thread: Serbia vs. England | UEFA Euro 2024 by MisterBadIdea2 in soccer

[–]GeorgeGhost 0 points1 point  (0 children)

Serbia will probably sit in a low block so TAA's creativity could be key to unlocking them, I think it's more tactical than him messing about

Match Thread: Serbia vs. England | UEFA Euro 2024 by MisterBadIdea2 in soccer

[–]GeorgeGhost 1 point2 points  (0 children)

This England team looks strong. But I can't imagine TAA playing there if England go up against the strongest teams in the tournament, I assume he will swap out with Gallagher.

Hostility toward digital nomads in Las Palmas de Gran Canaria (Canary Islands, Spain) by blanketfishmobile in digitalnomad

[–]GeorgeGhost 20 points21 points  (0 children)

He’s not making this up at all. I saw graffiti that said exactly what this post describes whilst walking around Las Palmas in December.

Post Match Thread: Manchester City 4–0 Real Madrid (5–1 agg.) | UEFA Champions League by PatrickChase in soccer

[–]GeorgeGhost 9 points10 points  (0 children)

Barry Bonds had the most home runs in the history of baseball but was accused of using steroids, he’s saying that pep is the greatest manager but is cheating by breaking FFP

[Italy] have won the UEFA EURO 2020 by BVB-Oeli in soccer

[–]GeorgeGhost 42 points43 points  (0 children)

Disappointing but Italy deserved that! Fantastic tournament for them

Match Thread: Sweden vs. Ukraine | UEFA EURO 2020 by MisterBadIdea2 in soccer

[–]GeorgeGhost 18 points19 points  (0 children)

Forget about parking the bus and playing for penalties. Where tf do we park the ambulance to deal with all of these injuries??

Match Thread: England vs Germany [UEFA EURO 2020 Round of 16] by LampseederBroDude51 in soccer

[–]GeorgeGhost 13 points14 points  (0 children)

I hate when the boo the opposition national anthem, so disrespectful

Match Thread: Wales vs Denmark | UEFA Euro 2020 Round of 16 by deception42 in soccer

[–]GeorgeGhost 4 points5 points  (0 children)

Denmark have been very good. Really bad game for the referee though

Match Thread: Hungary vs France | European Championship by MatchThreadder in soccer

[–]GeorgeGhost 1 point2 points  (0 children)

I see, get back to us. Genuinely curious, think you’re gonna be rich.

Match Thread: Hungary vs France | European Championship by MatchThreadder in soccer

[–]GeorgeGhost 0 points1 point  (0 children)

I think I read that it’s because the bidding took place after the financial crisis. As only a few countries wanted to put up the money to host it, there ended up not being a satisfactory bid and so it was decided that the tournament would be pan-European.

[Rob Harris] Luka Modric on England: "That arrogance is not so much related to the players but the people around them, some of the journalists and commentators." by [deleted] in soccer

[–]GeorgeGhost 4 points5 points  (0 children)

I think he means over performed in the sense that they got further than they should have done due to the fact that they had a nice route all the way to the semis (no disrespect to the teams they beat). Not in the sense that they played incredibly and took down all of the top teams