<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dmytro</title>
    <description>The latest articles on DEV Community by Dmytro (@bi_kaizen).</description>
    <link>https://dev.to/bi_kaizen</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3801912%2F13d90339-aa7f-4563-a0a4-d2e84107aac9.webp</url>
      <title>DEV Community: Dmytro</title>
      <link>https://dev.to/bi_kaizen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bi_kaizen"/>
    <language>en</language>
    <item>
      <title>What I Learned Building a Habit Tracker with React + AWS Amplify Gen 2</title>
      <dc:creator>Dmytro</dc:creator>
      <pubDate>Mon, 02 Mar 2026 15:35:50 +0000</pubDate>
      <link>https://dev.to/bi_kaizen/what-i-learned-building-a-habit-tracker-with-react-aws-amplify-gen-2-5dge</link>
      <guid>https://dev.to/bi_kaizen/what-i-learned-building-a-habit-tracker-with-react-aws-amplify-gen-2-5dge</guid>
      <description>&lt;p&gt;I've been building &lt;a href="https://bikaizen.com" rel="noopener noreferrer"&gt;Bi Kaizen&lt;/a&gt; (a minimalist habit tracker) as a side project over the past few months. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;React 19 + TypeScript + Vite&lt;/li&gt;
&lt;li&gt;AWS Amplify Gen 2 (AppSync/GraphQL, DynamoDB, Lambda, Cognito)&lt;/li&gt;
&lt;li&gt;TanStack React Query 5 for caching and optimistic updates&lt;/li&gt;
&lt;li&gt;Tailwind CSS&lt;/li&gt;
&lt;li&gt;dnd-kit for drag-and-drop habit reordering&lt;/li&gt;
&lt;li&gt;i18next for EN / UK / RU support&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Here's what I ran into and what actually worked.
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Amplify Gen 2 has a silent pagination bug you need to fix manually
&lt;/h3&gt;

&lt;p&gt;The code-first schema is genuinely better than YAML/JSON — you get typed GraphQL operations for free and it feels like real engineering. But there's a nasty default behavior that bit me hard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The problem&lt;/strong&gt;: Amplify's owner-based auth (allow.owner()) applies authorization after the DynamoDB query, not during it. That means when a user calls listHabits, AppSync executes a full table scan - iterating through every record from every user - hits DynamoDB's pagination limit (e.g. 1MB of data), and then filters down to just the records owned by the current user. If your table has enough data, a user with 10 habits might get 0 returned, because all 10 were beyond the pagination cutoff.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fix&lt;/strong&gt;: Manually add a GSI (Global Secondary Index) on the owner field in your Amplify schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// amplify/data/resource.ts
const schema = a.schema({
  Habit: a
    .model({
      name: a.string().required(),
      // ...other fields
    })
    .authorization((allow) =&amp;gt; [allow.owner()])
    .secondaryIndexes((index) =&amp;gt; [
      index("owner")  // &amp;lt;-- this is what saves you
    ]),
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this index, DynamoDB queries by owner first - only your records are touched, pagination works correctly, and the query is O(your data) instead of O(everyone's data).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is not mentioned prominently in the Amplify docs.&lt;/strong&gt; You'll only discover it when a user reports missing data or you notice your list queries returning fewer items than expected. Add the index from day one.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Optimistic UI is table stakes for a habit tracker
&lt;/h3&gt;

&lt;p&gt;Nobody wants to wait 300ms for a checkbox to visually toggle. TanStack Query makes this straightforward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mutation = useMutation({
  mutationFn: createCompletion,
  onMutate: async (newCompletion) =&amp;gt; {
    await queryClient.cancelQueries({ queryKey: queryKeys.completions(date) });
    const previous = queryClient.getQueryData(queryKeys.completions(date));
    queryClient.setQueryData(queryKeys.completions(date), (old) =&amp;gt; [...old, newCompletion]);
    return { previous };
  },
  onError: (_, __, context) =&amp;gt; {
    queryClient.setQueryData(queryKeys.completions(date), context.previous);
  },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key is a centralized queryKeys.ts file. Once you have more than 3 or 4 query types, ad-hoc key strings become a maintenance headache.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Scheduling logic is harder than it looks
&lt;/h3&gt;

&lt;p&gt;Supporting "every day", "weekdays only", "every 3 days", and "custom weekly days" means your calendar heatmap needs to know which days a habit was supposed to run before it can color them correctly.&lt;/p&gt;

&lt;p&gt;All of that lives in my dateUtils.ts and is the most-tested part of the app. If you're building something similar - &lt;code&gt;write tests for your date logic first.&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Pre-rendering beats SSR for static landing pages
&lt;/h3&gt;

&lt;p&gt;The app is a fully authenticated SPA, but the landing page needs to be crawlable by Google. Instead of adding SSR complexity, I use Puppeteer in a prerender script.&lt;br&gt;
The static HTML files get deployed alongside the SPA. Google sees real content; users get the React app. Simple.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Multi-language hreflang is fiddly but important
&lt;/h3&gt;

&lt;p&gt;Supporting Ukrainian, Russian, and English means:&lt;/p&gt;

&lt;p&gt;Separate pre-rendered pages at /, /uk, /ru&lt;br&gt;
hreflang tags in index.html&lt;br&gt;
Sitemap entries for all three&lt;br&gt;
Language-specific H1s (Google reads them for locale ranking)&lt;br&gt;
The &lt;a href="https://technicalseo.com/tools/hreflang/" rel="noopener noreferrer"&gt;hreflang validator&lt;/a&gt; is your friend.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd do differently
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Start with auth earlier. I built a lot of UI before wiring up Cognito and had to redo state management.&lt;/li&gt;
&lt;li&gt;Use a Lambda for bulk ops from day one. I added it later and had to migrate data.&lt;/li&gt;
&lt;li&gt;Write date utils tests before the UI. Every bug I had was in scheduling logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you track habits or want to try a clean, ad-free tracker: &lt;a href="https://bikaizen.com" rel="noopener noreferrer"&gt;bikaizen.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy to answer questions about any part of the stack.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flbjcqhp06nzoanpdv9jo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flbjcqhp06nzoanpdv9jo.png" alt="Bi Kaizen Heatmap" width="512" height="1141"&gt;&lt;/a&gt; &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw8d3hby5egq6qzp9wa8j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw8d3hby5egq6qzp9wa8j.png" alt="Bi Kaizen Checklist" width="511" height="1142"&gt;&lt;/a&gt; &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk53z9l0bp3uly09wysar.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk53z9l0bp3uly09wysar.png" alt="Bi Kaizen Streaks" width="512" height="1139"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>aws</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
