<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Posts tagged #react query</title><description>All posts tagged with react query on queen.raae.codes</description><link>https://queen.raae.codes/tag/react-query/</link><item><title>📝 ✨ ~ React Query pagination with Gatsby (File System Route API)</title><link>https://queen.raae.codes/2023-01-04-react-query-pagination/</link><guid isPermaLink="true">https://queen.raae.codes/2023-01-04-react-query-pagination/</guid><description>For Prune your follows, we already had an URL structure for filters like this: - /app/filter/unpopular - /app/filter/unfollowed - /app/filter/unpopular But for…</description><pubDate>Wed, 04 Jan 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;For &lt;a href=&quot;https://pruneyourfollows.com&quot;&gt;Prune your follows&lt;/a&gt;, we already had an URL structure for filters like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://pruneyourfollows.com/app/filter/unpopular&quot;&gt;/app/filter/unpopular&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://pruneyourfollows.com/app/filter/unfollowed&quot;&gt;/app/filter/unfollowed&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://pruneyourfollows.com/app/filter/unpopular&quot;&gt;/app/filter/unpopular&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But for most filters, there are more than 60 accounts, so we added pagination by:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Capturing the page number using the Gatsby File System Route API 1️⃣&lt;/li&gt;
&lt;li&gt;Extending the React Query cache key with the page number 2️⃣&lt;/li&gt;
&lt;li&gt;Calculating an offset using the page number 3️⃣&lt;/li&gt;
&lt;li&gt;Passing along the offset with our query for filtered accounts 4️⃣&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-jsx&quot;&gt;// ./src/pages/app/filter/[filter]/[...page].js 👈👈👈 1️⃣

import React from &amp;quot;react&amp;quot;;
import axios from &amp;quot;axios&amp;quot;;
import { useQuery } from &amp;quot;@tanstack/react-query&amp;quot;;

export default function SearchPage(props) {
  const pageIndex = parseInt(props.page) || 0;
  const size = 60;
  const offset = pageIndex * size; //👈👈👈 3️⃣
  const { data } = useQuery({
    queryKey: [&amp;quot;accounts&amp;quot;, props.filter, props.page], // 👈👈👈 2️⃣
    queryFn: ({ signal }) =&amp;gt;
      axios.get(&amp;quot;/api/accounts&amp;quot;, {
        params: {
          size: size,
          filter: props.filter,
          offset: offset, //👈👈👈 4️⃣
        },
        signal: signal,
      }),
    select: (result) =&amp;gt; result.data,
  });

  return (
    &amp;lt;ul&amp;gt;
      {(data?.records || []).map((record) =&amp;gt; (
        &amp;lt;li key={record.accountId}&amp;gt;
          {record.name} @{record.username}
        &amp;lt;/li&amp;gt;
      ))}
    &amp;lt;/ul&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If &amp;quot;capturing the page number using the Gatsby File System Route API&amp;quot; made no sense, then &lt;a href=&quot;/2022-12-01-url-based-pagination/&quot;&gt;Url-based (client-side) pagination with Gatsby&lt;/a&gt; is for you.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;All the best,&lt;br&gt;
Queen Raae&lt;/p&gt;
&lt;br/&gt;&lt;ul&gt;&lt;li&gt;Contrary to popular belief, Queen Raae and family have never worked for Gatsby.&lt;/li&gt;&lt;/ul&gt;</content:encoded></item><item><title>🏝 🗓 ~ This week around the Gatsby islands</title><link>https://queen.raae.codes/2022-01-10-this-week/</link><guid isPermaLink="true">https://queen.raae.codes/2022-01-10-this-week/</guid><description>I had somehow convinced myself this is the week I turn 40, but alas its another year before I can join the rank of the older and wiser 🤪 This week there are…</description><pubDate>Mon, 10 Jan 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I had somehow convinced myself this is the week I turn 40, but alas its another year before I can join the rank of the older and wiser 🤪&lt;/p&gt;
&lt;p&gt;This week there are two interesting webinars back to back on Thursday. One by Gatsby on &lt;a href=&quot;https://www.gatsbyjs.com/resources/webinars/gatsby-peak-frontend-performance&quot;&gt;Peak Frontend Performance&lt;/a&gt; and one on &lt;a href=&quot;https://cfe.dev/events/managing-remote-state-react/&quot;&gt;Managing Remote State w/ React Query&lt;/a&gt;. The latter is not Gatsby specific, but Gatsby + React Query = a Nice Setup.&lt;/p&gt;
&lt;p&gt;I&apos;ll have to watch them both after the fact, as Thursday is also the day for our unauthorized and rum-fueled &lt;a href=&quot;https://youtu.be/D_03KW4AkSk&quot;&gt;treasure hunt&lt;/a&gt; in the sharky waters around the Gatsby islands.&lt;/p&gt;
&lt;p&gt;Last week fellow &lt;a href=&quot;https://bloggingfordevs.com/pro/&quot;&gt;Blogging for Devs&lt;/a&gt; member Philo Hermans released &lt;a href=&quot;https://www.producthunt.com/posts/unlock-7&quot;&gt;Unlock&lt;/a&gt;. A product that should take all the pain out of selling software, including npm packages.&lt;/p&gt;
&lt;p&gt;I think this could be a solution for those of us wanting to sell Gatsby Plugins...&lt;/p&gt;
&lt;h2&gt;Our streaming schedule this week&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://youtu.be/D_03KW4AkSk&quot;&gt;🔴 👩‍🏫 Static Site Generation (SSG) with #GatsbyJS · Live Screencast&lt;/a&gt; — Tuesday, January 11th @ 14:00 CET&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://youtu.be/Wipi2lw6Mvc&quot;&gt;🔴 🐶 Let&apos;s help Mirjam with #ConferenceBuddy v2.0&lt;/a&gt; — Thursday, January 13th @ 19:00 CET&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://youtu.be/4fQj3YNKYoQ&quot;&gt;🔴 ⛵️ Working on the art site for the Pirate Princess · #OlaCast &lt;/a&gt; — Sunday, January 16th @ 11:30 CET&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Other events&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;My birthday — Tuesday, January 11th 🥳&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.gatsbyjs.com/resources/webinars/gatsby-peak-frontend-performance&quot;&gt;Achieving Peak Frontend Performance with Gatsby&lt;/a&gt; — Thursday, January 13th @ 17:00 CET · Gatsby&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cfe.dev/events/managing-remote-state-react/&quot;&gt;Managing Remote State w/ React Query&lt;/a&gt; — Thursday, January 13th @ 19:00 CET · cfe.dev&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;br&gt;
All the best,&lt;br&gt;
Queen Raae&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
&lt;strong&gt;PS:&lt;/strong&gt; If you have any tips for next week, let me know!&lt;/p&gt;
</content:encoded></item></channel></rss>