<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Özer on Medium]]></title>
        <description><![CDATA[Stories by Özer on Medium]]></description>
        <link>https://medium.com/@ozergklp?source=rss-295a8df77d27------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yJSSiB0E80yukEofKJZqww.jpeg</url>
            <title>Stories by Özer on Medium</title>
            <link>https://medium.com/@ozergklp?source=rss-295a8df77d27------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 06:05:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ozergklp/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to render code videos with React]]></title>
            <link>https://medium.com/@ozergklp/how-to-render-code-videos-with-react-0506d298f791?source=rss-295a8df77d27------2</link>
            <guid isPermaLink="false">https://medium.com/p/0506d298f791</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[webdev]]></category>
            <dc:creator><![CDATA[Özer]]></dc:creator>
            <pubDate>Sat, 16 May 2026 17:39:42 GMT</pubDate>
            <atom:updated>2026-05-16T17:43:13.255Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*EYFy09GbJC9oSQGngsfxBw.gif" /></figure><p>Most developers share code as screenshots. Carbon, ray.so, a quick crop from VS Code. They look fine, but they sit still in a feed full of motion, and most people scroll past.</p><p>A short video of the same code, typing itself out, behaves very differently. It catches the eye for the first second, which is usually all you need.</p><p>You can build this with React. The library is <a href="https://www.remotion.dev/">Remotion</a>. Once you understand two things, that a frame is just a function of time, and that React already gives you everything else, the rest is small.</p><p>This post walks through a minimal version: a typing animation with syntax highlighting, rendered to MP4. Around 100 lines.</p><h3>Why React for video</h3><p>Remotion treats a video as a React tree. You write components. The library renders them once per frame and stitches the frames into a video file. There is no timeline panel, no keyframes, no After Effects.</p><p>Two hooks do most of the work:</p><ul><li>useCurrentFrame() returns the current frame number.</li><li>interpolate(frame, [from, to], [a, b]) maps that frame to any animated value.</li></ul><p>Everything else is React you already know.</p><h3>Setting up</h3><pre>npm create video@latest -- --template hello-world cd my-code-video npm run dev</pre><p>This opens Remotion Studio at localhost:3000. The studio is just a preview; the source of truth is src/Composition.tsx. Replace its contents as we go.</p><p>The entry point registers a composition (width, height, fps, duration) and points it at a component:</p><p>That is the whole config for a 4-second 1080×1920 vertical video at 30 fps.</p><h3>Syntax highlighting without the async trap</h3><p>Remotion renders frames synchronously. Shiki, the highlighter, loads its themes and grammars asynchronously. If you call it inside a component, the first frame renders with no colors.</p><p>The fix is delayRender / continueRender. You tell Remotion to pause until your data is ready:</p><p>Now the first frame is colored, and Remotion does not start rendering until Shiki has loaded.</p><h3>The typing animation</h3><p>The trick is that the visible substring of the code is a function of the frame:</p><p>Frame 0 shows nothing. Frame 90 shows the full snippet. Frames in between show a growing prefix. clamp keeps it pinned to the end so the last 30 frames are a steady &quot;finished&quot; state, useful for the eye to land and read.</p><p>interpolate does linear easing by default. Pass easing: Easing.out(Easing.cubic) if you want it to slow down at the end, which feels more like real typing.</p><h3>Loading a real font</h3><p>System monospace varies across platforms, and on AWS Lambda or any headless renderer you cannot rely on it at all. Load a font explicitly:</p><p>@remotion/google-fonts is build-aware. It registers the font with the renderer so it shows up correctly during headless rendering.</p><h3>A blinking cursor (optional, 6 lines)</h3><p>That is all. The cursor is just a div whose visibility flips every 15 frames.</p><h3>Rendering to MP4</h3><pre>npx remotion render src/index.ts CodeVideo out/video.mp4</pre><p>The first render is slow because Chromium boots once. After that, frames render in parallel across CPU cores. A 4-second 1080×1920 video on a laptop takes 10 to 20 seconds.</p><p>For vertical platforms (TikTok, Reels, Shorts), keep the 1080×1920 composition. For Twitter or a blog header, change the composition to 1920×1080 and you are done. Same component, different framing.</p><h3>Where to take this</h3><p>The piece above is the floor. Things you can layer on, each maybe a weekend:</p><ul><li><strong>Line-by-line reveal</strong> instead of character-by-character. Feels less frantic for longer snippets.</li><li><strong>Diff mode</strong>. Two versions of the code, the deletions fade out, the additions fade in. The diff npm package gives you the line ops; the rest is interpolate.</li><li><strong>Token burst</strong>. Shiki returns tokens with positions; you can animate each one independently.</li><li><strong>Keystroke audio</strong>. &lt;Audio /&gt; component with a short click sample, played on every character increment.</li><li><strong>Backgrounds</strong>. Gradients, particles, a subtle drift. Just CSS or SVG, animated with interpolate.</li></ul><p>Each of these is its own post. The core never changes: a frame is a function of time, and React handles the rest.</p><h3>A short aside</h3><p>I built all of the above for myself, then realized I did not want to copy-paste Remotion configs every time I wanted to post a snippet. So I packaged it as a small web app called <a href="https://code2clip.com/">code2clip</a>: paste code, pick a theme and aspect ratio, get an MP4. If this tutorial reads like more weekend than you have, that exists. If it does not, the Remotion approach above is the whole picture; you do not need a tool.</p><h3>Closing</h3><p>Code screenshots are not going away, and they should not. But for the specific case of a developer feed (Twitter, LinkedIn, TikTok, Shorts), a 10-second video of code typing itself out behaves measurably differently from a static image. The infrastructure to build one is small, and you already know most of it.</p><p>What format are you using for code right now: screenshots, gifs, video? Curious whether anyone else has tested the same snippet in two formats.</p><p><em>Originally published at </em><a href="https://dev.to/ddoemonn/how-to-render-code-videos-with-react-44nh"><em>https://dev.to</em></a><em> on May 16, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0506d298f791" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Frontend Engineering Isn’t Dying. It’s Finally Growing Up.]]></title>
            <link>https://medium.com/@ozergklp/frontend-engineering-isnt-dying-it-s-finally-growing-up-5429936c8028?source=rss-295a8df77d27------2</link>
            <guid isPermaLink="false">https://medium.com/p/5429936c8028</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Özer]]></dc:creator>
            <pubDate>Sun, 26 Apr 2026 20:45:33 GMT</pubDate>
            <atom:updated>2026-04-26T20:45:33.290Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XJO_CTPembGpQtf5ft5ZQg.png" /><figcaption>Why the discipline everyone keeps writing eulogies for is about to matter more than it ever has.</figcaption></figure><p>Every few months, a new wave of takes washes over the timeline. <em>AI is killing frontend. Anyone can build a UI now. v0 made you obsolete. Why hire a frontend engineer in 2026?</em></p><p>I want to make a different argument. Not the cope version (“don’t worry, your job is safe”), and not the doomer version (“we’re all cooked”). Both are lazy.</p><p>Frontend engineering has spent a decade being underestimated. People treated it as the easy part of the stack. AI is the thing that finally exposes how wrong that framing was. Not because AI fails at frontend. It’s quite good at it. But because in failing in specific, visible, expensive ways, it teaches the rest of the industry what frontend engineers were quietly doing all along.</p><p>The job isn’t going away. The pretenders are.</p><h3>The Jevons argument, briefly</h3><p>In 1865, the economist William Stanley Jevons noticed that as steam engines got more efficient, Britain didn’t burn less coal. It burned vastly more. Cheaper per unit consumption unlocked uses that had not been economical before, and total demand exploded.</p><p>The same pattern plays out every time a new technology lowers the cost of producing software. Spreadsheets were supposed to end accountants. ATMs were supposed to end bank tellers. Cloud was supposed to end ops engineers. Each prediction was wrong in the same way. Efficiency expanded the market faster than it shrank the workforce.</p><p>The data on AI coding looks identical. Inference costs collapsed roughly 92% between early 2023 and 2026. Software engineering job postings ended 2025 growing significantly faster than overall postings. Enterprise AI spending tripled in the same period.</p><p>The curve goes up <em>in aggregate</em>. Whether <em>you</em> are on the right side of it depends on what kind of frontend engineer you are.</p><h3>What AI is genuinely good at</h3><p>Let’s be honest, because pretending the tools are worse than they are will get you blindsided.</p><p>v0 ships clean React and Tailwind code with shadcn/ui that you can paste into a Next.js project with minimal cleanup. Lovable can scaffold a working full stack app in an afternoon. A 2025 study put AI assisted developers at 21% faster on realistic tasks. McKinsey put the macro range at 20 to 45% productivity gains across the SDLC.</p><p>If your job was “translate a Figma frame into JSX, hook up a few props, ship it,” that job is being eaten. Not in five years. Now.</p><p>But every honest review of these tools surfaces the same gap. AI generated code works but lacks the structure, error handling, and optimization production needs. Tools struggle with edge cases and existing codebases. Lovable hits a wall the moment your business logic gets weird.</p><p>And the part nobody who hasn’t shipped a product wants to admit. AI generated UI looks like AI generated UI. There is now an entire cottage industry of “anti slop” skills (Taste Skill, UI Craft, getdesign.md) whose only purpose is to stop coding agents from producing the same beige, purple gradient, centered hero, shadcn default interface that every other vibe coded SaaS shipped this quarter. The fact that these tools exist, and have tens of thousands of stars, is the proof. Generic is cheap. Generic is not what makes a product win.</p><h3>The thing AI doesn’t have</h3><p>Strip away the framework discourse and frontend engineering is three things.</p><p><strong>Taste.</strong> Knowing which of fifty plausible layouts is right for <em>this</em> product, <em>this</em> user. Knowing why Stripe’s forms feel different from a generic shadcn form even though they use the same primitives. A junior with Stripe’s full design tokens still ships ugly dashboards. A senior with only grayscale ships something refined. The difference isn’t what they have. It’s what they know to do with it.</p><p><strong>Judgment under constraint.</strong> Real frontend work is not “build a pricing page.” It’s “build a pricing page that loads under 1.5s on a Moto G4, ranks for these keywords, A/B tests cleanly, doesn’t break the design system or accessibility, and ships before Tuesday.” AI can hit any one of those constraints. Holding all of them at once, while negotiating which to relax, is a context problem. Context is exactly what AI agents struggle with most.</p><p><strong>Translation between humans and systems.</strong> Every interface is a contract between the user’s mental model and your backend’s actual capabilities. Knowing what error states feel insulting versus helpful, when to confirm versus just do it, when to hide latency versus expose it. None of that is in the prompt.</p><p>If your value was “I know React,” the floor is dropping. If your value was taste, judgment, and translation, the ceiling is rising.</p><h3>The role is being renamed in real time</h3><p>While “frontend developer” postings have gotten weird (some sources show pure frontend down about 15% from 2024), demand for one subspecialty has gone vertical. <strong>Design engineering.</strong></p><p>Vercel, Linear, Stripe, Figma, half the YC batch. They are all hiring design engineers, and paying more than traditional frontend roles. The work is the same craft good frontend engineers were already doing in their best hours. The title is finally catching up.</p><p>The leverage point in an AI assisted org isn’t “fewer frontend engineers.” It’s “the few we have need to build the rails the AI runs on.” Someone has to author the registry, define the tokens, write the SKILL.md that tells the agent what good looks like. That someone is a senior frontend engineer with strong design sensibility, and their decisions get amplified across every AI generated component the team ever ships.</p><p>In one sentence. <strong>The frontend engineer used to be the person who wrote the components. Now they’re the person who decides what good components are.</strong></p><h3>What’s at risk, and why I’m still bullish</h3><p>The junior pipeline is in genuine trouble. Stanford found employment for developers aged 22 to 25 declined nearly 20% from its late 2022 peak. UK entry level tech roles fell 46% in 2024. The “translate Figma to JSX” bottom rung is partially dissolving.</p><p>If you’re senior, the next five years are likely the best of your career. If you’re trying to get in, the path has changed shape. You don’t get hired for tutorial completion anymore. You get hired for taste, for shipped projects, for evidence you can hold the whole problem in your head. Build things in public. Maintain something. Care about details that don’t show up in tickets.</p><p>Caring about details is one of the few things AI cannot bid against you on. Every “anti slop” tool the AI ecosystem produces is an admission of what humans with taste do for free.</p><h3>TL;DR</h3><ol><li><strong>Demand for software is super elastic.</strong> Cheaper software means more software, not less.</li><li><strong>The commodity layer is being automated, fast.</strong> If your value was framework fluency, you’re competing with a $20 a month subscription.</li><li><strong>The craft layer is appreciating.</strong> Taste, judgment, accessibility, performance, interaction detail. The things that make AI UI look generic are what companies will pay a premium for.</li><li><strong>The role is renaming itself.</strong> Design engineer. Design systems engineer. UI infrastructure. Same job. More senior than before.</li><li><strong>Juniors have a harder ladder, but a higher ceiling.</strong> What AI took in grunt work, it gave back as leverage. Use it.</li></ol><p>Frontend engineering isn’t dying. The rest of the industry is finally realizing what the job actually was.</p><p>The people who were always doing the real work are about to look very, very expensive.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5429936c8028" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why existing React color pickers frustrated me (and what I built instead)]]></title>
            <link>https://medium.com/@ozergklp/why-existing-react-color-pickers-frustrated-me-and-what-i-built-instead-da47a17ea2b0?source=rss-295a8df77d27------2</link>
            <guid isPermaLink="false">https://medium.com/p/da47a17ea2b0</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Özer]]></dc:creator>
            <pubDate>Sun, 31 Aug 2025 19:54:17 GMT</pubDate>
            <atom:updated>2025-08-31T19:54:17.817Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0-n66xDgh89jQ5MtdoR5UA.jpeg" /></figure><p>After building dozens of React applications, I thought choosing a color picker would be simple. Just grab a popular library from npm, import it, and move on, right? Wrong. Every existing solution I tried left me frustrated, leading me to build another library and here’s why.</p><h3>The monolithic problem that started it all</h3><p>Most React color pickers give you a single, rigid component that looks something like this:</p><pre>&lt;ColorPicker /&gt;</pre><p>That’s it. One big, inflexible box with everything baked in. Want to move the hue slider above the saturation area? Too bad. Need to add your own custom controls between the picker and the sliders? Not happening. Want to create a compact horizontal layout for mobile? Sorry, you’re stuck with whatever the library designer thought was best.</p><p>The frustration: Every design system is different, but color pickers force you to accept their vision or hack around it with brittle CSS overrides.</p><h3>The layout inflexibility problem</h3><p>Here’s what really bothered me: I needed a color picker for a design tool where the layout requirements kept changing. Sometimes I needed a compact horizontal layout, sometimes vertical, sometimes I wanted to inject custom controls between components.</p><p>Every library I tried gave me a pre-built layout with limited customization options. Want the alpha slider above the hue? Not possible. Need to add a custom preset palette between the saturation area and sliders? Good luck with CSS hacks.</p><p>The frustration: Why can’t I just arrange the color picker components exactly how my design needs them?</p><h3>The CSS override nightmare</h3><p>Most color pickers come with their own CSS that you have to fight against. Want to match your design system’s border radius? Override their styles. Need custom spacing? More CSS overrides. Dark mode? Hope they thought of that.</p><p>I spent more time wrestling with CSS specificity and !important declarations than actually building features. The color picker should work with your design system, not against it.</p><p>The frustration: Why am I fighting the library’s CSS when I just want to pick colors?</p><h3>State management that fights you</h3><p>Here’s a scenario that drove me crazy: I’m building a design tool where users work in HSL values, but every color picker I tried would:</p><p>1. Take my HSL input</p><p>2. Convert it internally to RGB or HSV</p><p>3. Give me back a completely different HSL value due to rounding errors</p><p>4. Force me to manage the “drift” between what the user input and what I get back</p><p>Want to initialize with { h: 240, s: 100, l: 50 } and get back exactly that format? Good luck. Most libraries have their own internal state management that assumes you want whatever format they prefer.</p><p>The frustration: I know what format I want. Why won’t you just give it to me?</p><h3>What I built instead: react-beautiful-color</h3><p>After hitting these walls repeatedly, I decided to build something different. Here’s how react-beautiful-color solves each of these problems:</p><h3>Compound components that actually compose</h3><p>Instead of one giant component, you get composable pieces:</p><pre>&lt;ColorPicker color={colorInput} onChange={setColor}&gt;<br>  &lt;ColorPicker.Saturation className=&quot;flex-1 mb-3&quot; /&gt;<br>  <br>  &lt;div className=&quot;flex items-center gap-3 p-3 pt-0&quot;&gt;<br>    &lt;ColorPicker.EyeDropper&gt;<br>      &lt;Pipette /&gt;<br>    &lt;/ColorPicker.EyeDropper&gt;<br>    <br>    &lt;div className=&quot;flex-1 flex flex-col gap-3&quot;&gt;<br>      &lt;ColorPicker.Hue className=&quot;h-4&quot; /&gt;<br>      &lt;ColorPicker.Alpha className=&quot;h-4&quot; /&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/ColorPicker&gt;</pre><p>Want the hue slider on top? Move it. Need a custom layout? Build it. Want to add your own controls? Drop them anywhere. You control the layout, not the library.</p><h3>True compound component architecture</h3><p>Unlike other libraries that give you one monolithic component, react-beautiful-color is built from the ground up as composable pieces. Each part (Saturation, Hue, Alpha, EyeDropper) is an independent component that you can arrange however you want.</p><p>Need a custom layout? Compose it. Want to add your own components between pieces? Drop them in. Building a design system with specific spacing requirements? You control every aspect of the layout.</p><h3>Format preservation that actually works</h3><p>The useColorState hook preserves your input format while giving you all formats instantly:</p><pre>const [{ colorInput, colorState }, setColor] = useColorState({ <br>  type: &#39;hsl&#39;, h: 240, s: 100, l: 50 <br>});<br><br>// colorInput stays as HSL - no format drift!<br>console.log(colorInput); // { type: &#39;hsl&#39;, h: 240, s: 100, l: 50 }<br><br>// But you get all formats instantly<br>console.log(colorState.hex);  // &quot;#0000ff&quot;<br>console.log(colorState.rgb);  // { r: 0, g: 0, b: 255 }<br>console.log(colorState.hsv);  // { h: 240, s: 100, v: 100 }</pre><p>No conversion drift. No state fighting. Just the format you want, when you want it.</p><h3>Tailwind-first styling approach</h3><p>Instead of shipping custom CSS that you have to override, react-beautiful-color uses pure Tailwind classes. Your design system uses Tailwind? Perfect integration. Custom design tokens? Just pass different classes. Dark mode? It just works.</p><p>No CSS overrides, no specificity wars, no style conflicts. The components are unstyled by default and accept whatever Tailwind classes you want to apply.</p><h3>Modern browser APIs</h3><p>Built-in support for the EyeDropper API means users can pick colors directly from their screen — no complex implementations or polyfills required.</p><h3>TypeScript from day one</h3><p>Complete type safety with discriminated unions means you catch color format errors at compile time, not runtime. IntelliSense works perfectly, and refactoring is safe.</p><h3>The result: happiness</h3><p>Building with react-beautiful-color feels different. Instead of fighting the library, you’re composing with it. Instead of working around limitations, you’re building exactly what you need.</p><p>The compound component pattern means every use case I’ve encountered from simple color inputs to complex design tools can be built elegantly without hacks or workarounds.</p><p>You get a truly flexible compound component API that adapts to your design system instead of forcing your design system to adapt to it. Every component is independently stylable, positionable, and composable.</p><p>Sometimes the best solution isn’t finding the perfect library — it’s building the library you wish existed.</p><p>Documentation and examples: <a href="http://react-beautiful-color.dev/">react-beautiful-color.dev</a></p><p>Try react-beautiful-color in your next project:</p><pre>npm install react-beautiful-color</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da47a17ea2b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerizing Any Frontend Project]]></title>
            <link>https://medium.com/@ozergklp/dockerizing-any-frontend-project-e0a0172c3303?source=rss-295a8df77d27------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0a0172c3303</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Özer]]></dc:creator>
            <pubDate>Thu, 05 Sep 2024 20:10:32 GMT</pubDate>
            <atom:updated>2024-09-06T06:30:09.118Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BlaPcMdKPNGNyVrsFyICMQ.png" /><figcaption><a href="https://www.lamalab.agency/">Lama Lab</a></figcaption></figure><p>I’ve been having trouble with Docker and don’t know much about it yet. I want to learn how to use Docker for frontend projects. In this guide, I’ll explain what Docker is and why it’s useful for frontend developers and then I’ll give a simple method to set up Docker for any frontend framework. Lastly, I’ll show you how to use Docker with popular frameworks like React, Angular, and Vue.</p><h3>What is Docker?</h3><p>Docker is a tool that helps you quickly build, test, and run apps. Imagine how hard and time-consuming it is to manually install and set up apps on your computer. Docker simplifies this by using a file called a Dockerfile, which creates a Docker image. This image includes everything the app needs to run, so you don’t have to install or set up anything extra. With Docker, you can run any app easily without extra steps.</p><h3>Why frontend developers should consider using Docker?</h3><p>Frontend developers should use Docker because it makes setting up and managing development environments easier. You don’t need to worry about different setups on different computers. Docker ensures that your app runs the same way everywhere, so you can test and run it in a consistent environment. This helps avoid problems and conflicts.</p><h3>Simple solution for integrating Docker with any frontend framework</h3><p>To integrate Docker with any frontend framework, follow these simple steps:</p><ol><li><strong>Create a Dockerfile</strong>: This file tells Docker how to build your application. It typically includes:</li></ol><ul><li><strong>Base Image</strong>: Start with a basic Node.js image (like node:alpine).</li><li><strong>Set Up Workspace</strong>: Define where Docker will work inside the container.</li><li><strong>Install Dependencies</strong>: Copy and install your project’s dependencies.</li><li><strong>Add Your Code</strong>: Copy the rest of your project files into the container.</li><li><strong>Build Your App</strong>: Run the build command for your project.</li><li><strong>Expose Port</strong>: Specify the port your app will run on.</li><li><strong>Start the Server</strong>: Define the command to start your app.</li></ul><p>2. <strong>Build the Docker Image</strong>: Use this command to create a Docker image from your Dockerfile:</p><pre>docker build -t your-image-name .</pre><p>3. <strong>Run the Docker Container</strong>: Start a container from your image with this command:</p><pre>docker run -p [HOST_PORT]:[CONTAINER_PORT] your-image-name</pre><p>Replace [HOST_PORT] with the port on your local machine where you want to access the app, and [CONTAINER_PORT] with the port your app runs on inside the container.</p><h3>React with Docker</h3><h4>Dockerfile</h4><pre>FROM node:alpine<br><br>WORKDIR /usr/src/app<br><br>COPY package*.json ./<br><br>RUN npm install<br><br>COPY . .<br><br>RUN npm run build<br><br>EXPOSE 5173<br><br>CMD [&quot;npm&quot;, &quot;run&quot;, &quot;dev&quot;, &quot;--&quot;, &quot;--host&quot;]</pre><h4>Commands</h4><pre>sudo docker build -t react-docker .</pre><pre>docker run -p 5173:5173 react-docker</pre><h3>Vue with Docker</h3><p>Dockerizing a Vue project is similar to Dockerizing a React project. Here’s the Dockerfile and commands for Vue:</p><h4>Dockerfile</h4><pre>FROM node:alpine<br><br>WORKDIR /usr/src/app<br><br>COPY package*.json ./<br><br>RUN npm install<br><br>COPY . .<br><br>RUN npm run build<br><br>EXPOSE 5173<br><br>CMD [&quot;npm&quot;, &quot;run&quot;, &quot;dev&quot;, &quot;--&quot;, &quot;--host&quot;]</pre><h4>Commands</h4><pre>sudo docker build -t vue-docker .</pre><pre>docker run -p 5173:5173 vue-docker</pre><h3>Angular with Docker</h3><p>Dockerizing an Angular project involves a few differences since Angular uses port 4200 and the Angular CLI for serving. Here’s the Dockerfile and commands for Angular:</p><h4>Dockerfile</h4><pre>FROM node:alpine<br><br>WORKDIR /usr/src/app<br><br>COPY . /usr/src/app<br><br>EXPOSE 4200<br><br>RUN npm install -g @angular/cli<br><br>RUN npm install<br><br>CMD [&quot;ng&quot;, &quot;serve&quot;, &quot;--host&quot;, &quot;0.0.0.0&quot;]</pre><h4>Commands</h4><pre>sudo docker build -t angular-docker .</pre><pre>docker run -p 4200:4200 angular-docker</pre><h3>Summary</h3><p>This guide shows you how to create Docker containers for any frontend framework, with examples for Angular, React, and Vue. It explains the basics of setting up a Dockerfile, building an image, and running the container. If you look at the commands and Dockerfile, you’ll see that the process is similar for any frontend library. There are more advanced steps for real projects, but this guide’s goal is to help you understand why and how to use Docker with any frontend framework. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0a0172c3303" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Zustand with Supabase and Next.js App Router?]]></title>
            <link>https://medium.com/@ozergklp/how-to-use-zustand-with-supabase-and-next-js-app-router-0473d6744abc?source=rss-295a8df77d27------2</link>
            <guid isPermaLink="false">https://medium.com/p/0473d6744abc</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[supabase]]></category>
            <category><![CDATA[zustand]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Özer]]></dc:creator>
            <pubDate>Sun, 18 Aug 2024 13:10:52 GMT</pubDate>
            <atom:updated>2024-08-19T04:43:04.250Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lgi5DkEXAjTeAnyreKEdiw.png" /><figcaption><a href="https://www.lamalab.agency/">Lama Lab</a></figcaption></figure><h3>Introduction</h3><p>Recently, I was building a social media app and chose Supabase for the database, Zustand for state management, and Next.js for server-side rendering capabilities. In this case, I want to show you how you can update your database while immediately reflecting changes to your users. Let’s get started!</p><h3>Sections</h3><ul><li>Creating the Post Interface</li><li>Creating the Zustand Store for Posts</li><li>Server Actions for the Home Page</li><li>Creating a Post for Both Supabase and Zustand</li><li>Creating Home Page Component</li><li>Showing Posts to Users</li></ul><h3>Creating the Post Interface</h3><p>First, we need to create the Post interface to ensure that the types are correct for our project, states, and database.</p><pre>//types/Post.ts<br>interface Post {<br>  id: number;<br>  content: string;<br>  userId: number;<br>  created_at: string;<br>  avatarUrl: string;<br>  userName: string;<br>  name: string;<br>}</pre><h3>Creating the Zustand Store for Posts</h3><p>We have created our interface. Now, with the Post interface, we can create a Zustand store to use our posts in different components.</p><pre>//store/index.ts<br>import { create } from &#39;zustand&#39;;<br><br>import { createClient } from &#39;@/utils/supabase/client&#39;;<br><br>const supabase = createClient();<br><br>interface PostStore {<br>  posts: Post[];<br>  fetchPosts: () =&gt; Promise&lt;void&gt;;<br>  addPost: (post: Post) =&gt; void;<br>}<br><br>export const usePostStore = create&lt;PostStore&gt;(set =&gt; ({<br>  posts: [],<br>  fetchPosts: async () =&gt; {<br>    const { data, error } = await supabase.from(&#39;posts&#39;).select(&#39;*&#39;);<br>    if (error) {<br>      console.error(&#39;Error fetching posts:&#39;, error);<br>    } else {<br>      set({ posts: data });<br>    }<br>  },<br>  addPost: post =&gt; set(state =&gt; ({ posts: [...state.posts, post] })),<br>}));<br><br>const postStore = usePostStore.getState();<br>postStore.fetchPosts();</pre><p>As you can see, we also have a PostStore interface to define usePostStore. With usePostStore, we can create, set, and use posts in any component in our project. Additionally, we initially fetch posts from Supabase to dynamically link our store to the database.</p><h3>Server Actions for the Home Page</h3><p>We need to interact with server actions within our form to insert a post into our Supabase table. Let’s define our actions!</p><pre>//modules/HomePage/actions.ts<br>export async function createPost(formData: FormData): Promise&lt;Post[]&gt; {<br>  const supabase = createClient();<br><br>  const content = formData.get(&#39;content&#39;) as string;<br><br>  if (!content) {<br>    throw new Error(&#39;Content is required&#39;);<br>  }<br><br>  const { data, error } = await supabase<br>    .from(&#39;posts&#39;)<br>    .insert({<br>      content,<br>      userId: user.id,<br>      avatarUrl: user.user_metadata.avatar_url,<br>      userName: user.user_metadata.user_name,<br>      name: user.user_metadata.full_name,<br>      tags,<br>    })<br>    .select()<br>    .returns&lt;Post[]&gt;();<br><br>  if (error) {<br>    throw new Error(error.message);<br>  }<br><br>  return data;<br>}</pre><p>The important part of this code is that we are returning a Promise&lt;Post[]&gt;. After we insert a post, we select the post, and Supabase returns the inserted post within a single-element array. We will see how to use actions with Zustand in the next section.</p><h3>Creating a Post for Both Supabase and Zustand</h3><p>We have defined our action; now we need to actually create a post for both our store and the database. Note that I’m using a Drawer component in my real codebase, so don&#39;t worry about the naming here—it&#39;s just a component that allows us to create a post. Let&#39;s inspect the code!</p><pre>//modules/HomePage/CreatePostDrawer.tsx<br>&#39;use client&#39;;<br><br>import { usePostStore } from &#39;@/store&#39;;<br><br>import { createPost } from &#39;./actions&#39;;<br><br>export default function CreatePostDrawer() {<br>  const addPost = usePostStore(state =&gt; state.addPost);<br><br>  return (<br>    //... existing content<br>          &lt;form<br>            action={async e =&gt; {<br>              const newPost = await createPost(e, tagsList);<br>              if (newPost) {<br>                addPost(newPost[0]);<br>              }<br>            }}<br>          &gt;<br>             &lt;Textarea<br>                      name=&quot;content&quot;<br>                      placeholder=&quot;Type your message here.&quot;<br>              /&gt;<br>          &lt;/form&gt;<br>    //... existing content<br>  );<br>}</pre><p>Here, we are retrieving addPost from our store. Inside the form action, we first update our database. After that, as I mentioned, it returns a promise, and with that promise, we add a new post to our store. Note that Supabase returns a single-element array, so we need to access the new post with newPost[0].</p><h3>Creating Home Page Component</h3><pre>//modules/HomePage/index.tsx<br>import { PostgrestSingleResponse } from &#39;@supabase/supabase-js&#39;;<br><br>import { createClient } from &#39;@/utils/supabase/server&#39;;<br><br>import CreatePostDrawer from &#39;./CreatePostDrawer&#39;;<br>import Posts from &#39;./Posts&#39;;<br><br>export default async function HomePage() {<br>  return (<br>    &lt;main&gt;<br>      &lt;Posts/&gt;<br>      &lt;CreatePostDrawer /&gt;<br>    &lt;/main&gt;<br>  );<br>}</pre><p>Here, we don’t need to fetch posts from Supabase directly; we’re essentially handling the initial render as mentioned. Now, let’s see the fun part: how we show our posts to users!</p><h3>Showing Posts to Users</h3><p>In the component, you will see the Image, Link components from Next.js, and dayjs. For now, let&#39;s not focus on them. We need to focus on how we are using Zustand to update posts immediately and how we put posts into the Zustand store on the first render.</p><pre>//modules/HomePage/Posts.tsx<br>&#39;use client&#39;;<br><br>import { useEffect } from &#39;react&#39;;<br><br>import Image from &#39;next/image&#39;;<br>import Link from &#39;next/link&#39;;<br><br>import { PostgrestSingleResponse } from &#39;@supabase/supabase-js&#39;;<br>import dayjs from &#39;dayjs&#39;;<br>import relativeTime from &#39;dayjs/plugin/relativeTime&#39;;<br>dayjs.extend(relativeTime);<br><br>import { usePostStore } from &#39;@/store&#39;;<br><br>interface PostsProps {<br>  posts: PostgrestSingleResponse&lt;Post[]&gt;;<br>}<br><br>export default function Posts({ posts }: PostsProps) {<br>  const postsFromStore = usePostStore(state =&gt; state.posts);<br><br>  return (<br>    &lt;&gt;<br>      {postsFromStore.map(post =&gt; (<br>        &lt;div<br>          key={post.id}<br>        &gt;<br>          &lt;div&gt;<br>            &lt;Link href={`/profile/${post.userName}`}&gt;<br>              &lt;Image<br>                src={post.avatarUrl}<br>                alt=&quot;avatar&quot;<br>                width={60}<br>                height={60}<br>              /&gt;<br>            &lt;/Link&gt;<br>            &lt;div&gt;<br>              &lt;div&gt;<br>                &lt;Link<br>                  href={`/profile/${post.userName}`}<br>                &gt;<br>                  {post.name}<br>                &lt;/Link&gt;<br>                &lt;div&gt;@{post.userName}&lt;/div&gt;<br>                &lt;div&gt; {dayjs(post.created_at).fromNow()} &lt;/div&gt;<br>              &lt;/div&gt;<br>              &lt;div&gt;{post.content}&lt;/div&gt;<br>            &lt;/div&gt;<br>          &lt;/div&gt;<br>        &lt;/div&gt;<br>      ))}<br>    &lt;/&gt;<br>  );<br>}</pre><p>Here, actually, the component explains itself very briefly after our iterations. On the first render, if posts exist from Supabase, we update our store, and we use the posts from the store in the component. That’s all. We have seen how we can use server actions, Zustand, and Supabase together.</p><h3>Summary</h3><p>I think for fresh starters, it’s a good and simple real-life example of how to use Next.js App Router, Zustand, and Supabase together for creating and showing posts to users. I am open to any feedback to improve this approach. Feel free to comment! Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0473d6744abc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Simple Counter Application with Yew.rs ]]></title>
            <link>https://medium.com/@ozergklp/building-a-simple-counter-application-with-yew-rs-b0eca7242f93?source=rss-295a8df77d27------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0eca7242f93</guid>
            <category><![CDATA[counter]]></category>
            <category><![CDATA[yew]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[Özer]]></dc:creator>
            <pubDate>Fri, 24 May 2024 15:03:20 GMT</pubDate>
            <atom:updated>2024-05-29T19:20:04.152Z</atom:updated>
            <content:encoded><![CDATA[<h4>Empowering Rust: From Command Line to Web Frontend with Yew.rs</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*seBl1FFcKalXI6fu3-VT0A.png" /><figcaption><a href="https://lamalab.agency/">Lama Lab</a></figcaption></figure><h3>Introduction</h3><p>Rust, known for its robustness in system programming, is making waves in the world of web development through frameworks like Yew.rs. In this tutorial, we’ll walk through building a basic counter application using Yew.rs, showcasing how Rust can be leveraged for frontend development.</p><h3>Prerequisites</h3><p>Ensure you have Rust and Cargo installed on your system.</p><h3>Creating the Project</h3><p>Let’s start by setting up our project. Open your terminal and create a new Cargo project:</p><pre>cargo new yew-app<br>cd yew-app</pre><h4>Updating Cargo.toml:</h4><p>Add Yew to the list of dependencies in your Cargo.toml:</p><pre>[dependencies]<br>yew = { git = &quot;https://github.com/yewstack/yew/&quot;, features = [&quot;csr&quot;] }</pre><h3>Step by Step Explanation</h3><h4>1. Imports</h4><pre>use yew::prelude::*;</pre><p>We import the necessary modules from Yew.rs to build our application.</p><h4>2. Component Definition</h4><pre>#[function_component]<br>fn App() -&gt; Html {</pre><p>The App function defines our main component using the #[function_component] macro. It returns HTML (Html) and represents the root of our application.</p><h4>3. State Management</h4><pre>let counter = use_state(|| 0);</pre><p>We use the use_state hook to create a state variable counter initialized to 0. This hook returns a tuple containing the state variable and a function to update it</p><h4>4. Event Handlers</h4><pre>let increment = {<br>    let counter = counter.clone();<br>    move |_| {<br>        let value = *counter + 1;<br>        counter.set(value);<br>    }<br>};<br><br>let decrement = {<br>    let counter = counter.clone();<br>    move |_| {<br>        let value = *counter - 1;<br>        counter.set(value);<br>    }<br>};</pre><p>Two event handler functions, increment and decrement, are defined to handle the logic for increasing and decreasing the counter value, respectively. These functions are closures that capture the counter state variable and update it accordingly.</p><h4>5. HTML Structure</h4><pre>html! {<br>    &lt;div style=&quot;text-align: center; margin-top: 50px;&quot;&gt;<br>        &lt;button style=&quot;padding: 10px 20px; font-size: 18px; margin-right: 10px; background-color: #4CAF50; color: white; border: none; border-radius: 5px;&quot; onclick={increment}&gt;{ &quot;+1&quot; }&lt;/button&gt;<br>        &lt;button style=&quot;padding: 10px 20px; font-size: 18px; background-color: #f44336; color: white; border: none; border-radius: 5px;&quot; onclick={decrement}&gt;{ &quot;-1&quot; }&lt;/button&gt;<br>        &lt;p style=&quot;font-size: 24px; margin-top: 20px;&quot;&gt;{ *counter }&lt;/p&gt;<br>    &lt;/div&gt;<br>}</pre><p>Inside the html! macro, we define the structure of our UI. It consists of two buttons for incrementing and decrementing the counter, along with a paragraph to display the current counter value. Event handlers are attached to the buttons using the onclick attribute.</p><h4>6. Rendering</h4><pre>fn main() {<br>    yew::Renderer::&lt;App&gt;::new().render();<br>}</pre><p>In the main function, we create a new instance of the Renderer for our App component and call the render method to render the component on the web page.</p><h4>7. Final Code with Explanation</h4><pre>use yew::prelude::*;<br><br>#[function_component]<br>fn App() -&gt; Html {<br>    let counter = use_state(|| 0);<br><br>    let increment = {<br>        let counter = counter.clone();<br>        move |_| {<br>            let value = *counter + 1;<br>            counter.set(value);<br>        }<br>    };<br><br>    let decrement = {<br>        let counter = counter.clone();<br>        move |_| {<br>            let value = *counter - 1;<br>            counter.set(value);<br>        }<br>    };<br><br>    html! {<br>        &lt;div style=&quot;text-align: center; margin-top: 50px;&quot;&gt;<br>            &lt;button style=&quot;padding: 10px 20px; font-size: 18px; margin-right: 10px; background-color: #4CAF50; color: white; border: none; border-radius: 5px;&quot; onclick={increment}&gt;{ &quot;+1&quot; }&lt;/button&gt;<br>            &lt;button style=&quot;padding: 10px 20px; font-size: 18px; background-color: #f44336; color: white; border: none; border-radius: 5px;&quot; onclick={decrement}&gt;{ &quot;-1&quot; }&lt;/button&gt;<br>            &lt;p style=&quot;font-size: 24px; margin-top: 20px;&quot;&gt;{ *counter }&lt;/p&gt;<br>        &lt;/div&gt;<br>    }<br>}<br><br>fn main() {<br>    yew::Renderer::&lt;App&gt;::new().render();<br>}</pre><p>This code creates a simple counter application using Yew.rs, demonstrating how Rust can be utilized for frontend web development. It showcases the power of Rust’s expressive syntax and strong type system in building robust web applications.</p><h3>Viewing Your Web Application</h3><pre>trunk serve --open</pre><p>This command will open your default browser to view the application. Trunk will automatically rebuild your application if you modify any source code files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*4uDyEUoDdlOlIknfIMNuuQ.jpeg" /><figcaption>Our Final Web Application</figcaption></figure><h3>Conclusion</h3><p>Congratulations! You&#39;ve successfully set up your Yew development environment and built your first web application using Rust. Dive deeper into Yew&#39;s capabilities and explore more examples to enhance your understanding and skills in Rust-based frontend development.</p><p><a href="https://medium.com/lamalab">lamalab</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0eca7242f93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All React 19 Features in One Place]]></title>
            <link>https://medium.com/@ozergklp/all-react-19-features-in-one-place-b61e55eb669f?source=rss-295a8df77d27------2</link>
            <guid isPermaLink="false">https://medium.com/p/b61e55eb669f</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-19]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Özer]]></dc:creator>
            <pubDate>Mon, 20 May 2024 07:48:34 GMT</pubDate>
            <atom:updated>2024-05-29T19:20:22.592Z</atom:updated>
            <content:encoded><![CDATA[<p>React 19 is the newest version of the React . It comes with lots of new features and improvements . These updates help developers work faster and make their apps run smoother. In this guide, we’ll go through each of these new features with examples to show how they can be used in your projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CywuQzff89wal58LH-6ETw.png" /><figcaption><a href="https://lamalab.agency/">Lama Lab</a></figcaption></figure><h3>Features</h3><ul><li>action</li><li>use</li><li>useContext</li><li>useFormState</li><li>useFormStatus</li><li>useOptimistic</li><li>useTransition</li></ul><h3>1. action</h3><h4>Purpose of code blocks:</h4><p>The blocks illustrate how to handle form submissions, where users can input a title and message, and submit the form to add a new post.</p><h4>Traditional use case</h4><pre>const PostForm = ({ addPost }) =&gt; {<br>  const [formData, setFormData] = useState({<br>    title: &#39;&#39;,<br>    body: &#39;&#39;<br>  });<br><br>  const handleChange = (event) =&gt; {<br>    setFormData({<br>      ...formData,<br>      [event.target.name]: event.target.value<br>    });<br>  };<br><br>  const handleSubmit = (event) =&gt; {<br>    event.preventDefault();<br>    const newPost = {<br>      title: formData.title,<br>      body: formData.body,<br>    };<br>    addPost(newPost);<br>    setFormData({<br>      title: &#39;&#39;,<br>      body: &#39;&#39;<br>    });<br>  };<br><br>  return (<br>    &lt;form<br>      onSubmit={handleSubmit}<br>    &gt;<br>      &lt;div className=&#39;mb-4&#39;&gt;<br>        &lt;label<br>          htmlFor=&#39;title&#39;<br>        &gt;<br>          Title<br>        &lt;/label&gt;<br>        &lt;input<br>          id=&#39;title&#39;<br>          type=&#39;text&#39;<br>          placeholder=&#39;Enter title&#39;<br>          name=&#39;title&#39;<br>          value={formData.title}<br>          onChange={handleChange}<br>        /&gt;<br>      &lt;/div&gt;<br>      &lt;div className=&#39;mb-6&#39;&gt;<br>        &lt;label<br>          htmlFor=&#39;body&#39;<br>        &gt;<br>          Body<br>        &lt;/label&gt;<br>        &lt;textarea<br>          id=&#39;body&#39;<br>          rows=&#39;5&#39;<br>          placeholder=&#39;Enter body&#39;<br>          name=&#39;body&#39;<br>          value={formData.body}<br>          onChange={handleChange}<br>        &gt;&lt;/textarea&gt;<br>      &lt;/div&gt;<br>      &lt;div&gt;<br>        &lt;button<br>          type=&#39;submit&#39;<br>        &gt;<br>          Submit<br>        &lt;/button&gt;<br>      &lt;/div&gt;<br>    &lt;/form&gt;<br>  );<br>};<br><br></pre><h4>React 19 use case</h4><pre>const PostForm = ({ addPost }) =&gt; {<br>  const formAction = async (formData) =&gt; {<br>    const newPost = {<br>      title: formData.get(&#39;title&#39;),<br>      body: formData.get(&#39;body&#39;),<br>    };<br><br>    addPost(newPost);<br>  };<br><br>  return (<br>    &lt;form action={formAction}&gt;<br>      &lt;div&gt;<br>        &lt;label htmlFor=&#39;title&#39;&gt;Title&lt;/label&gt;<br>        &lt;input<br>          type=&#39;text&#39;<br>          placeholder=&#39;Enter title&#39;<br>          name=&#39;title&#39;<br>        /&gt;<br>      &lt;/div&gt;<br>      &lt;div&gt;<br>        &lt;label htmlFor=&#39;body&#39;&gt;Body&lt;/label&gt;<br>        &lt;textarea<br>          rows=&#39;5&#39;<br>          placeholder=&#39;Enter body&#39;<br>          name=&#39;body&#39;<br>        &gt;&lt;/textarea&gt;<br>      &lt;/div&gt;<br>      &lt;div&gt;<br>        &lt;button type=&#39;submit&#39;&gt;Submit&lt;/button&gt;<br>      &lt;/div&gt;<br>    &lt;/form&gt;<br>  );<br>};</pre><h4>Differences:</h4><ul><li>Traditional approach involves managing form state with useState and handling form submission with a dedicated function, manually resetting the form after submission.</li><li>React 19 simplifies this by using the action attribute directly in the form to handle submissions, eliminating the need for useState and manual state management.</li></ul><h3>2. use</h3><h4>Purpose of code blocks:</h4><p>The blocks demonstrate how to fetch data from an API and display it within a React component.</p><h4>Traditional use case</h4><pre>import { useEffect, useState } from &#39;react&#39;;<br><br>const Item = ({ item }) =&gt; {<br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;{item.value}&lt;/h2&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>const Component = () =&gt; {<br>  const [item, setItem] = useState([]);<br>  const [loading, setLoading] = useState(true);<br><br>  useEffect(() =&gt; {<br>    const fetchItem = async () =&gt; {<br>      try {<br>        const res = await fetch(&#39;apiUrl&#39;);<br>        const data = await res.json();<br>        setItem(data);<br>        setLoading(false);<br>      } catch (error) {<br>        console.error(error);<br>      } finally {<br>        setLoading(false);<br>      }<br>    };<br><br>    fetchJoke();<br>  }, []);<br><br>  if (loading) {<br>    return &lt;h2&gt;Loading...&lt;/h2&gt;;<br>  }<br><br>  return &lt;Item item={item} /&gt;;<br>};<br></pre><h4>React 19 use case</h4><pre>import { use, Suspense } from &#39;react&#39;;<br><br>const fetchData = async () =&gt; {<br>  const res = await fetch(&#39;apiUrl&#39;);<br>  return res.json();<br>};<br><br>const Item = () =&gt; {<br>  const item = use(fetchData());<br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;{item.value}&lt;/h2&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>const Component = () =&gt; {<br>  return (<br>    &lt;Suspense<br>      fallback={<br>        &lt;h2&gt;Loading...&lt;/h2&gt;<br>      }<br>    &gt;<br>      &lt;Item /&gt;<br>    &lt;/Suspense&gt;<br>  );<br>};</pre><h4>Differences:</h4><ul><li>Traditional approach uses useState and useEffect to fetch data, manage loading states, and update component state.</li><li>React 19 introduces the use hook, which simplifies data fetching by allowing data to be fetched declaratively. This approach, combined with Suspense, automatically handles loading states, leading to cleaner and more concise code.</li></ul><h3>3. useContext</h3><h4>Purpose of code blocks:</h4><p>The blocks show how to consume a theme context within a React component and toggle between light and dark themes.</p><pre>import { createContext, useState, useContext } from &#39;react&#39;;<br><br>const ThemeContext = createContext();<br><br>const ThemeProvider = ({ children }) =&gt; {<br>  const [theme, setTheme] = useState(&#39;light&#39;);<br><br>  const toggleTheme = () =&gt; {<br>    setTheme((prevTheme) =&gt; (prevTheme === &#39;light&#39; ? &#39;dark&#39; : &#39;light&#39;));<br>  };<br><br>  return (<br>    &lt;ThemeContext.Provider value={{ theme, toggleTheme }}&gt;<br>      {children}<br>    &lt;/ThemeContext.Provider&gt;<br>  );<br>};<br><br>const ThemedCard = () =&gt; {<br>  const context = useContext(ThemeContext);<br><br>  return (<br>    &lt;div<br>      className={`max-w-md mx-auto shadow-md rounded-lg p-6 ${<br>        context.theme === &#39;light&#39; ? &#39;bg-white&#39; : &#39;bg-gray-800&#39;<br>      }`}<br>    &gt;<br>      &lt;h1<br>        className={`text-2xl mb-3 ${<br>          context.theme === &#39;light&#39; ? &#39;text-gray-800&#39; : &#39;text-white&#39;<br>        }`}<br>      &gt;<br>        Themed Card<br>      &lt;/h1&gt;<br>      &lt;p className={context.theme === &#39;light&#39; ? &#39;text-gray-800&#39; : &#39;text-white&#39;}&gt;<br>        Long Paragraph<br>      &lt;/p&gt;<br>      &lt;button<br>        onClick={context.toggleTheme}<br>      &gt;<br>        {context.theme === &#39;light&#39; ? &#39;Switch to Dark Mode&#39; : &#39;Switch to Light Mode&#39;}<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>const Theme = () =&gt; {<br>  return (<br>    &lt;ThemeProvider&gt;<br>      &lt;ThemedCard /&gt;<br>    &lt;/ThemeProvider&gt;<br>  );<br>};</pre><h4>React 19 use case</h4><pre>import  { createContext, useState, use } from &#39;react&#39;;<br><br>const ThemeContext = createContext();<br><br>const ThemeProvider = ({ children }) =&gt; {<br>  const [theme, setTheme] = useState(&#39;light&#39;);<br><br>  const toggleTheme = () =&gt; {<br>    setTheme((prevTheme) =&gt; (prevTheme === &#39;light&#39; ? &#39;dark&#39; : &#39;light&#39;));<br>  };<br><br>  return (<br>    &lt;ThemeContext.Provider value={{ theme, toggleTheme }}&gt;<br>      {children}<br>    &lt;/ThemeContext.Provider&gt;<br>  );<br>};<br><br>const ThemedCard = () =&gt; {<br>  const { theme, toggleTheme } = use(ThemeContext);<br><br>  return (<br>    &lt;div<br>      className={`max-w-md mx-auto shadow-md rounded-lg p-6 ${<br>        theme === &#39;light&#39; ? &#39;bg-white&#39; : &#39;bg-gray-800&#39;<br>      }`}<br>    &gt;<br>      &lt;h1<br>        className={`text-2xl mb-3 ${<br>          theme === &#39;light&#39; ? &#39;text-gray-800&#39; : &#39;text-white&#39;<br>        }`}<br>      &gt;<br>        Themed Card<br>      &lt;/h1&gt;<br>      &lt;p className={theme === &#39;light&#39; ? &#39;text-gray-800&#39; : &#39;text-white&#39;}&gt;<br>        Long Paragraph<br>      &lt;/p&gt;<br>      &lt;button<br>        onClick={toggleTheme}<br>      &gt;<br>        {theme === &#39;light&#39; ? &#39;Switch to Dark Mode&#39; : &#39;Switch to Light Mode&#39;}<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>const Theme = () =&gt; {<br>  return (<br>    &lt;ThemeProvider&gt;<br>      &lt;ThemedCard /&gt;<br>    &lt;/ThemeProvider&gt;<br>  );<br>};</pre><h4>Differences:</h4><ul><li>Traditional method involves creating a context, using useContext within components, and manually managing context values.</li><li>React 19 allows direct use of context with the use hook, simplifying context consumption and reducing the amount of boilerplate code.</li></ul><h3>4. useFormState</h3><h4>Purpose of code blocks:</h4><p>The blocks compare how to handle form submissions and state management for adding items to a cart.</p><h4>Traditional use case</h4><pre>import  { useState } from &#39;react&#39;;<br><br>const AddToCartForm = ({ itemID, itemTitle }) =&gt; {<br>  const [message, setMessage] = useState(null);<br><br>  const handleSubmit = (event) =&gt; {<br>    event.preventDefault();<br>    const formData = new FormData(event.target);<br>    const message = addToCart(formData.get(&#39;itemID&#39;));<br>    setMessage(message);<br>  };<br><br>  return (<br>    &lt;form<br>      onSubmit={handleSubmit}<br>     <br>    &gt;<br>      &lt;h2&gt;{itemTitle}&lt;/h2&gt;<br>      &lt;input type=&#39;hidden&#39; name=&#39;itemID&#39; value={itemID} /&gt;<br>      &lt;button<br>        type=&#39;submit&#39;<br>      &gt;<br>        Add to Cart<br>      &lt;/button&gt;<br>      &lt;div&gt;{message}&lt;/div&gt;<br>    &lt;/form&gt;<br>  );<br>};<br><br>export default AddToCartForm;</pre><h4>React 19 use case</h4><pre>const AddToCartForm = ({ itemID, itemTitle }) =&gt; {<br>  const [message, formAction] = useFormState(addToCart, null);<br><br>  return (<br>    &lt;form<br>      action={formAction}<br>    &gt;<br>      &lt;h2&gt;{itemTitle}&lt;/h2&gt;<br>      &lt;input type=&#39;hidden&#39; name=&#39;itemID&#39; value={itemID} /&gt;<br>      &lt;button<br>        type=&#39;submit&#39;<br>      &gt;<br>        Add to Cart<br>      &lt;/button&gt;<br>      &lt;div&gt;{message}&lt;/div&gt;<br>    &lt;/form&gt;<br>  );<br>};<br><br>export default AddToCartForm;</pre><h4>Differences:</h4><ul><li>Traditional approach uses useState to manage form state and handle form submissions, displaying messages based on the submission outcome.</li><li>React 19 uses useFormState, which integrates form state management and submission handling, simplifying the form component and reducing the need for explicit state handling.</li></ul><h3>5. useFormStatus</h3><h4>Purpose of code blocks:</h4><p>The blocks illustrate handling form submission statuses, such as displaying a “Submitting…” message while a form is being processed.</p><h4>Traditional use case</h4><pre>import { useState } from &#39;react&#39;;<br><br>const SubmitButton = ({ disabled }) =&gt; {<br>  return (<br>    &lt;button<br>      type=&#39;submit&#39;<br>      disabled={disabled}<br>    &gt;<br>      {disabled ? &#39;Submitting...&#39; : &#39;Submit&#39;}<br>    &lt;/button&gt;<br>  );<br>};<br><br>const PostForm = ({ addPost }) =&gt; {<br>  const [isSubmitting, setIsSubmitting] = useState(false);<br><br>  const handleSubmit = async (event) =&gt; {<br>    event.preventDefault();<br>    setIsSubmitting(true);<br>    const formData = new FormData(event.target);<br>   <br>    await new Promise((resolve) =&gt; setTimeout(resolve, 2000));<br>    const newPost = {<br>      title: formData.get(&#39;title&#39;),<br>      body: formData.get(&#39;body&#39;),<br>    };<br>    addPost(newPost);<br>    setIsSubmitting(false);<br>  };<br><br>  return (<br>    &lt;form<br>      onSubmit={handleSubmit}<br>    &gt;<br>      &lt;div&gt;<br>        &lt;label<br>          htmlFor=&#39;title&#39;<br>        &gt;<br>          Title<br>        &lt;/label&gt;<br>        &lt;input<br>          id=&#39;title&#39;<br>          type=&#39;text&#39;<br>          placeholder=&#39;Enter title&#39;<br>          name=&#39;title&#39;<br>        /&gt;<br>      &lt;/div&gt;<br>      &lt;div&gt;<br>        &lt;label<br>          htmlFor=&#39;body&#39;<br>        &gt;<br>          Body<br>        &lt;/label&gt;<br>        &lt;textarea<br>          id=&#39;body&#39;<br>          rows=&#39;5&#39;<br>          placeholder=&#39;Enter body&#39;<br>          name=&#39;body&#39;<br>        &gt;&lt;/textarea&gt;<br>      &lt;/div&gt;<br>      &lt;div&gt;<br>        &lt;SubmitButton disabled={isSubmitting} /&gt;<br>      &lt;/div&gt;<br>    &lt;/form&gt;<br>  );<br>};<br><br>const Posts = () =&gt; {<br>  const [posts, setPosts] = useState([]);<br><br>  const addPost = (newPost) =&gt; {<br>    setPosts((posts) =&gt; [...posts, newPost]);<br>  };<br><br>  return (<br>    &lt;&gt;<br>      &lt;PostForm addPost={addPost} /&gt;<br>      {posts.map((post, index) =&gt; (<br>        &lt;PostItem key={index} post={post} /&gt;<br>      ))}<br>    &lt;/&gt;<br>  );<br>};<br></pre><h4>React 19 use case</h4><pre>import { useFormStatus } from &#39;react-dom&#39;;<br>import { useState } from &#39;react&#39;;<br><br>const SubmitButton = () =&gt; {<br>  const { pending } = useFormStatus();<br><br>  return (<br>    &lt;button<br>      type=&#39;submit&#39;<br>      disabled={pending}<br>    &gt;<br>      {pending ? &#39;Submitting...&#39; : &#39;Submit&#39;}<br>    &lt;/button&gt;<br>  );<br>};<br><br>const PostForm = ({ addPost }) =&gt; {<br>  const formAction = async (formData) =&gt; {<br>    await new Promise((resolve) =&gt; setTimeout(resolve, 2000));<br>    const newPost = {<br>      title: formData.get(&#39;title&#39;),<br>      body: formData.get(&#39;body&#39;),<br>    };<br><br>    addPost(newPost);<br>  };<br><br>  return (<br>    &lt;form<br>      action={formAction}<br>    &gt;<br>      &lt;div&gt;<br>        &lt;label<br>          htmlFor=&#39;title&#39;<br>        &gt;<br>          Title<br>        &lt;/label&gt;<br>        &lt;input<br>          id=&#39;title&#39;<br>          type=&#39;text&#39;<br>          placeholder=&#39;Enter title&#39;<br>          name=&#39;title&#39;<br>        /&gt;<br>      &lt;/div&gt;<br>      &lt;div&gt;<br>        &lt;label<br>          htmlFor=&#39;body&#39;<br>        &gt;<br>          Body<br>        &lt;/label&gt;<br>        &lt;textarea<br>          id=&#39;body&#39;<br>          rows=&#39;5&#39;<br>          placeholder=&#39;Enter body&#39;<br>          name=&#39;body&#39;<br>        &gt;&lt;/textarea&gt;<br>      &lt;/div&gt;<br>      &lt;div&gt;<br>        &lt;SubmitButton /&gt;<br>      &lt;/div&gt;<br>    &lt;/form&gt;<br>  );<br>};<br><br>const Posts = () =&gt; {<br>  const [posts, setPosts] = useState([]);<br><br>  const addPost = (newPost) =&gt; {<br>    setPosts((posts) =&gt; [...posts, newPost]);<br>  };<br><br>  return (<br>    &lt;&gt;<br>      &lt;PostForm addPost={addPost} /&gt;<br>      {posts.map((post, index) =&gt; (<br>        &lt;PostItem key={index} post={post} /&gt;<br>      ))}<br>    &lt;/&gt;<br>  );<br>};</pre><h4>Differences:</h4><ul><li>Traditional method requires managing submission status with useState and manually updating the button state and message during submission.</li><li>React 19 introduces useFormStatus, which tracks the form&#39;s pending state, allowing components to automatically update their UI based on the submission status.</li></ul><h3>6. useOptimistic</h3><h4>Purpose of code blocks:</h4><p>The blocks show how to optimistically update a message thread by displaying messages as “sending” before they are confirmed by the server.</p><h4>Traditional use case</h4><pre>import { useState, useRef } from &#39;react&#39;;<br><br>const MessageForm = ({ sendMessage }) =&gt; {<br>  const [message, setMessage] = useState(&#39;&#39;);<br>  const [sending, setSending] = useState(false);<br>  const formRef = useRef();<br><br>  const handleSubmit = async (event) =&gt; {<br>    event.preventDefault();<br>    if (!message.trim()) return;<br>    <br>    setSending(true);<br>    <br>    await sendMessage(message);<br><br>    formRef.current.reset();<br>    setSending(false);<br>  };<br><br>  const handleChange = (event) =&gt; {<br>    setMessage(event.target.value);<br>  };<br><br>  return (<br>    &lt;form onSubmit={handleSubmit} ref={formRef}&gt;<br>      &lt;input<br>        type=&#39;text&#39;<br>        name=&#39;message&#39;<br>        placeholder=&#39;Hello!&#39;<br>        value={message}<br>        onChange={handleChange}<br>      /&gt;<br>      &lt;button<br>        type=&#39;submit&#39;<br>        disabled={sending}<br>      &gt;<br>        Send<br>      &lt;/button&gt;<br>    &lt;/form&gt;<br>  );<br>};<br><br>const Thread = ({ messages }) =&gt; {<br>  return (<br>    &lt;div&gt;<br>      {messages.map((message) =&gt; (<br>        &lt;div key={message.id}&gt;<br>          &lt;span&gt;{message.text}&lt;/span&gt;<br>          {message.sending &amp;&amp; (<br>            &lt;small&gt;(Sending...)&lt;/small&gt;<br>          )}<br>        &lt;/div&gt;<br>      ))}<br>    &lt;/div&gt;<br>  );<br>};<br><br>const deliverMessage = async (message) =&gt; {<br>  await new Promise((res) =&gt; setTimeout(res, 1000));<br>  return message;<br>};<br><br>const MessageBox = () =&gt; {<br>  const [messages, setMessages] = useState([]);<br>  const nextId = useRef(1);<br><br>  async function sendMessage(message) {<br>    const newMessage = { id: nextId.current, text: message, sending: true };<br>    setMessages((prevMessages) =&gt; [...prevMessages, newMessage]);<br>    <br>    const sentMessage = await deliverMessage(message);<br>    setMessages((prevMessages) =&gt;<br>      prevMessages.map((msg) =&gt;<br>        msg.id === newMessage.id ? { ...msg, text: sentMessage, sending: false } : msg<br>      )<br>    );<br><br>    nextId.current++;<br>  }<br><br>  return (<br>    &lt;div&gt;<br>      &lt;MessageForm sendMessage={sendMessage} /&gt;<br>      &lt;Thread messages={messages} /&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><h4>React 19 use case</h4><pre>import { useOptimistic, useState, useRef } from &#39;react&#39;;<br><br>const MessageForm = ({ addOptimisticMessage, sendMessage }) =&gt; {<br>  const formRef = useRef();<br><br>  const formAction = async (formData) =&gt; {<br>    addOptimisticMessage(formData.get(&#39;message&#39;));<br><br>    formRef.current.reset();<br><br>    await sendMessage(formData);<br>  };<br><br>  return (<br>    &lt;form action={formAction} ref={formRef}&gt;<br>      &lt;input<br>        type=&#39;text&#39;<br>        name=&#39;message&#39;<br>        placeholder=&#39;Hello!&#39;<br>      /&gt;<br>      &lt;button<br>        type=&#39;submit&#39;<br>      &gt;<br>        Send<br>      &lt;/button&gt;<br>    &lt;/form&gt;<br>  );<br>};<br><br>const Thread = ({ messages, sendMessage }) =&gt; {<br>  const [optimisticMessages, addOptimisticMessage] = useOptimistic(<br>    messages,<br>    (state, newMessage) =&gt; [<br>      ...state,<br>      {<br>        text: newMessage,<br>        sending: true,<br>      },<br>    ]<br>  );<br><br>  return (<br>    &lt;div&gt;<br>      &lt;MessageForm<br>        addOptimisticMessage={addOptimisticMessage}<br>        sendMessage={sendMessage}<br>      /&gt;<br>      {optimisticMessages.map((message, index) =&gt; (<br>        &lt;div key={index} className=&#39;flex items-center&#39;&gt;<br>          &lt;span&gt;{message.text}&lt;/span&gt;<br>          {message.sending &amp;&amp; (<br>            &lt;small className=&#39;ml-1 text-gray-500&#39;&gt;(Sending...)&lt;/small&gt;<br>          )}<br>        &lt;/div&gt;<br>      ))}<br>    &lt;/div&gt;<br>  );<br>};<br><br>const deliverMessage = async (message) =&gt; {<br>  await new Promise((res) =&gt; setTimeout(res, 1000));<br>  return message;<br>};<br><br>const MessageBox = () =&gt; {<br>  const [messages, setMessages] = useState([]);<br><br>  async function sendMessage(formData) {<br>    const sentMessage = await deliverMessage(formData.get(&#39;message&#39;));<br><br>    setMessages((messages) =&gt; [...messages, { text: sentMessage }]);<br>  }<br><br>  return &lt;Thread messages={messages} sendMessage={sendMessage} /&gt;;<br>};</pre><h4>Differences:</h4><ul><li>Traditional approach involves managing message state with useState, handling form submissions, and manually updating the UI to reflect sending states.</li><li>React 19 uses useOptimistic, which simplifies managing optimistic updates by providing a more declarative way to update the UI while awaiting server confirmation.</li></ul><h3>7. useTransition</h3><h4>Purpose of code blocks:</h4><p>The blocks demonstrate how to update a user name and handle the pending state during the update process.</p><h4>Traditional use case</h4><pre>import { useState } from &#39;react&#39;;<br><br>async function updateName(name) {<br><br>  await new Promise(resolve =&gt; setTimeout(resolve, 2000));<br><br><br>  if (name.trim() !== &#39;&#39;) {<br>    return &#39;Name Updated&#39;; <br>  } else {<br>    return &quot;Name cannot be empty.&quot;; <br>  }<br>}<br><br>export default function UpdateName() {<br>  const [name, setName] = useState(&quot;&quot;);<br>  const [updateStatus, setUpdateStatus] = useState(&quot;&quot;);<br>  const [isPending, setIsPending] = useState(false);<br><br>  const handleSubmit = async () =&gt; {<br>    setIsPending(true);<br>    const result = await updateName(name);<br>    setIsPending(false);<br>    if (result == &quot;Name cannot be empty.&quot;) {<br>      setUpdateStatus(result);<br>      return;<br>    } <br>    else {<br>        setUpdateStatus(result);<br>    }<br><br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;input value={name} onChange={(event) =&gt; setName(event.target.value)} /&gt;<br>      &lt;button onClick={handleSubmit} disabled={isPending}&gt;<br>        {isPending ? &#39;Updating...&#39; : &#39;Update&#39;}<br>      &lt;/button&gt;<br>        {updateStatus &amp;&amp; &lt;p&gt;{updateStatus}&lt;/p&gt;}<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>React 19 use case</h4><pre>import { useState, useTransition } from &#39;react&#39;;<br><br>async function updateName(name) {<br>  await new Promise(resolve =&gt; setTimeout(resolve, 2000));<br><br>  if (name.trim() !== &#39;&#39;) {<br>    return &#39;Name Updated&#39;; <br>  } else {<br>    return &quot;Name cannot be empty.&quot;; <br>  }<br>}<br><br>export default function UpdateName() {<br>  const [name, setName] = useState(&quot;&quot;);<br>  const [updateStatus, setUpdateStatus] = useState(&quot;&quot;);<br>  const [isPending, startTransition] = useTransition();<br><br>  const handleSubmit = () =&gt; {<br>    startTransition(async () =&gt; {<br>        const result = await updateName(name);<br>        if (result == &quot;Name cannot be empty.&quot;) {<br>            setUpdateStatus(result);<br>            return;<br>        } <br>        else {<br>            setUpdateStatus(result);<br>            return;<br>        }<br>      <br>    })<br>  };<br><br><br>  return (<br>    &lt;div&gt;<br>      &lt;input value={name} onChange={(event) =&gt; setName(event.target.value)} /&gt;<br>      &lt;button onClick={handleSubmit} disabled={isPending}&gt;<br>        {isPending ? &#39;Updating...&#39; : &#39;Update&#39;}<br>      &lt;/button&gt;<br>      {updateStatus &amp;&amp; &lt;p&gt;{updateStatus}&lt;/p&gt;}<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>Differences:</h4><ul><li>Traditional approach uses useState to manage the pending state and manually update the UI during the asynchronous update process.</li><li>React 19 introduces useTransition, which simplifies managing pending UI states during transitions, improving user experience by keeping the UI responsive.</li></ul><h3>Summary</h3><p>React 19 introduces new features to simplify development, improve code readability, and enhance user experience. These include streamlined form handling, efficient data fetching with hooks like ‘use’, simplified context consumption, and smoother UI updates during transitions.</p><h3>References</h3><ul><li><a href="https://react.dev/blog/2024/04/25/react-19">https://react.dev/blog/2024/04/25/react-1</a></li><li><a href="https://youtu.be/EPaLg4U_K1o?si=wRZwzK-yinA6j2rq">https://youtu.be/EPaLg4U_K1o?si=wRZwzK-yinA6j2rq</a></li></ul><p><a href="https://medium.com/lamalab">lamalab</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b61e55eb669f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>