<?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: Quan Phan</title>
    <description>The latest articles on DEV Community by Quan Phan (@qhphan).</description>
    <link>https://dev.to/qhphan</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%2F1207561%2Fc1c23c9a-2514-4d61-adcb-73c988f5c847.jpeg</url>
      <title>DEV Community: Quan Phan</title>
      <link>https://dev.to/qhphan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/qhphan"/>
    <language>en</language>
    <item>
      <title>Product people! You'd love Cultural Probes in User Interviews</title>
      <dc:creator>Quan Phan</dc:creator>
      <pubDate>Fri, 22 Mar 2024 17:56:10 +0000</pubDate>
      <link>https://dev.to/qhphan/product-people-youd-love-cultural-probes-in-user-interviews-497a</link>
      <guid>https://dev.to/qhphan/product-people-youd-love-cultural-probes-in-user-interviews-497a</guid>
      <description>&lt;p&gt;That awkward transition from small talk ("&lt;em&gt;Hi! How are you? How's your week(end) been?&lt;/em&gt;") to the real interview ("&lt;em&gt;My first question for you is...&lt;/em&gt;"). It's not absolutely painful, but definitely NOT my favorite part of a user interview.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6aptf3ffma3lgw82q6t5.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6aptf3ffma3lgw82q6t5.jpeg" alt="Image description" width="750" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How can we make these first few minutes of the interview less awkward? Better yet, how might we utilize these first few minutes to "warm up" our users and open them up for the actual interview?&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing... cultural probes
&lt;/h2&gt;

&lt;p&gt;In our Design thinking class, my friends and I were running a semester-long project to solve a common problem among study abroad students. As part of our research, we wanted to know our users' goals for their semester-long study abroad experience.&lt;/p&gt;

&lt;p&gt;In one of my interviews with a double major in Computer Science and English who was studying abroad in London, I began by asking her to...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Draw me your goals this semester!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;She hesitated for a bit, then started drawing, all the while excused the "ugly" sketch (which I didn't think was the case!). After giggling at the result, she handed it over to me...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9779fku6kc0usson9ch7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9779fku6kc0usson9ch7.png" alt="Her goals this semester: Spending more time on writing and reading (on the left) and traveling the world (on the right)" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I pointed at the picture on the left: "Ooh... this looks interesting! Can you tell me more about it?" and effortlessly initiated the interview.&lt;/p&gt;

&lt;p&gt;I later on found out that the picture on the left was a notebook which represented her goal to spend more time on writing and reading. Despite being an English major, her high workload in Computer Science prevented her from writing and reading as much as she wanted. The picture on the right represented her aspirations to explore Europe and the world.&lt;/p&gt;

&lt;h2&gt;
  
  
  It doesn't have to be drawing!
&lt;/h2&gt;

&lt;p&gt;There's no one definition for cultural probes. They can be any activities that you ask your interviewee to do at the beginning of the interview that "tricks" them into opening up.&lt;/p&gt;

&lt;p&gt;In a project that aimed to facilitating find the best travel buddies, the team showed their users 8 personnas with different personality trade-offs. They used the users' ranking of these imaginary travel buddies to started the conversation.&lt;/p&gt;

&lt;p&gt;Another group, who aimed to support college students in balancing food budgeting and exploration while being abroad, asked people to guess the prices of different food items at the nearest grocery store. They later on examined how the discrepancy in their users' predictions and the actual prices affected food budgeting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why cultural probes?
&lt;/h2&gt;

&lt;p&gt;Cultural probes are powerful because:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;They distract your users from thinking about the interview and channeled their focus on an activity, and thereby, break the ice.&lt;/li&gt;
&lt;li&gt;At the end of the cultural probes, you have people's thoughts laid out in front of you, and you can poke wherever you like.&lt;/li&gt;
&lt;li&gt;An activity can elicit stories and emotions way better than a question can.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, next time you have an user interview, try come up with a creative cultural probes and involve your users. You might have a lot of fun while learning so much more about your users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Discussion
&lt;/h2&gt;

&lt;p&gt;What other cultural probes do you use to warm up your users for an interview?&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>design</category>
    </item>
    <item>
      <title>Zero-to-beginner front-end roadmap</title>
      <dc:creator>Quan Phan</dc:creator>
      <pubDate>Wed, 29 Nov 2023 21:18:51 +0000</pubDate>
      <link>https://dev.to/qhphan/zero-to-beginner-front-end-roadmap-88f</link>
      <guid>https://dev.to/qhphan/zero-to-beginner-front-end-roadmap-88f</guid>
      <description>&lt;p&gt;I recently updated my zero-to-beginner front-end developer roadmap. Check it out here: &lt;a href="https://bit.ly/47Tloxo"&gt;https://bit.ly/47Tloxo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are so many posts and videos on front-end roadmaps, but sometimes they are too overwhelming. You don't need to know every semantic tags in HTML or every array methods in JS before diving into React.&lt;/p&gt;

&lt;p&gt;Each step in my roadmap teaches you just enough to proceed to the next. The rest, you will pick up as you build your capstone projects. I think this way is much more fun than cramming an extra hour of video on features of JS you will never use.&lt;/p&gt;

&lt;p&gt;All the materials from my roadmap are from Youtube. Kudos to all the Youtubers out there that are lowering the entry bar to programming with their high-quality free tutorials.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Inside React useState</title>
      <dc:creator>Quan Phan</dc:creator>
      <pubDate>Fri, 24 Nov 2023 09:29:22 +0000</pubDate>
      <link>https://dev.to/qhphan/inside-react-usestate-n41</link>
      <guid>https://dev.to/qhphan/inside-react-usestate-n41</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Ever wonder how &lt;code&gt;useState&lt;/code&gt; works under the hood? Especially how a call to &lt;code&gt;setState&lt;/code&gt; can trigger a UI rendering? Let's take a peek into a simple implementation of &lt;code&gt;useState&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The simple implementation is taken from step 8 of &lt;a href="https://pomb.us/build-your-own-react/"&gt;"Build your own React" tutorial by Rodrigo Pombo&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Annex on the Fiber tree
&lt;/h2&gt;

&lt;p&gt;Understanding the Fiber tree data structure and the two Fiber trees used in React lifecycles, &lt;code&gt;current&lt;/code&gt; and &lt;code&gt;wip&lt;/code&gt;, are important to understand the code of &lt;code&gt;useState&lt;/code&gt;. I wrote extensively about the Fiber tree &lt;a href="https://dev.to/qhphan/build-your-own-react-fiber-tree-2kij"&gt;here&lt;/a&gt; and the two Fiber trees as part of the React lifecycle &lt;a href="https://dev.to/qhphan/build-your-own-react-rendering-commit-phases-1man"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here are a few important notes.&lt;/p&gt;

&lt;p&gt;Fiber tree is a tree data structure, where each node represents either a DOM node (&lt;code&gt;h1&lt;/code&gt;, &lt;code&gt;div&lt;/code&gt;, &lt;code&gt;p&lt;/code&gt;, etc.) or a functional component. The entire Fiber tree can be thought of as a representation of the virtual DOM.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;current&lt;/code&gt; tree reflects the DOM that is currently visible on the browser. When state is changed and a new render is triggered, the &lt;code&gt;wip&lt;/code&gt; tree can be thought of as a draft of the new DOM that is about to be rendered on the browser. Changes are made to this &lt;code&gt;wip&lt;/code&gt; throughout a render (thus, the name work-in-progress).&lt;/p&gt;

&lt;p&gt;There are two properties of a Fiber node that we care about. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;alternate&lt;/code&gt; field is a pointer to the corresponding node in the previous render. Okay, what does "corresponding" mean here?&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;hooks&lt;/code&gt; field points to an array of hooks associated with that node (so only nodes that represent functional components can have non-empty &lt;code&gt;hooks&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;useState&lt;/code&gt; under the hood
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Initiate the hook for the current rendering&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;oldHook&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="nx"&gt;wipFiber&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;alternate&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
        &lt;span class="nx"&gt;wipFiber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;alternate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hooks&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
        &lt;span class="nx"&gt;wipFiber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;alternate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hooks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;hookIndex&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hook&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;oldHook&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;oldHook&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="c1"&gt;// apply all the actions saved from last rendering&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;actions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;oldHook&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;oldHook&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;queue&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="nx"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;hook&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;hook&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// all the actions are pushed into the queue&lt;/span&gt;
        &lt;span class="nx"&gt;hook&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// set wipRoot to initiate the rendering&lt;/span&gt;
        &lt;span class="nx"&gt;wipRoot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;currentRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;currentRoot&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;alternate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;currentRoot&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;

        &lt;span class="nx"&gt;nextUnitOfWork&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;wipRoot&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;deletions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;hook&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Initiate the hook
&lt;/h2&gt;

&lt;p&gt;In the first render, the state of the hook will be initiated with &lt;code&gt;initial&lt;/code&gt; value. In subsequent renders, the state of the hook will be initiated as the state of the corresponding hook in the previous render.&lt;/p&gt;

&lt;p&gt;While the first sentence is straightforward, the second is a bit hard to see from the code. Let's zoom in...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;oldHook&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="nx"&gt;wipFiber&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;alternate&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
        &lt;span class="nx"&gt;wipFiber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;alternate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hooks&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
        &lt;span class="nx"&gt;wipFiber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;alternate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hooks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;hookIndex&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the &lt;code&gt;wipFiber&lt;/code&gt; tree, &lt;code&gt;wipFiber.alternate&lt;/code&gt; accesses the corresponding fiber node in the &lt;code&gt;current&lt;/code&gt; tree , and &lt;code&gt;wipFiber.alternate.hooks&lt;/code&gt; access the hooks of that node.&lt;/p&gt;

&lt;p&gt;The index of a hook in a functional component doesn't change through renders, we can use a global variable &lt;code&gt;hookIndex&lt;/code&gt; to track and retrieve the hook corresponding to the current hook in the previous render.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining &lt;code&gt;setState&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Now, let's look at the &lt;code&gt;setState&lt;/code&gt; function. When &lt;code&gt;setState&lt;/code&gt; is called with a callback function &lt;code&gt;action&lt;/code&gt;, the action is added to a &lt;code&gt;queue&lt;/code&gt; that is part of the hook. This queue will be unpacked in the next render, and each actions will be applied on the state. &lt;/p&gt;

&lt;p&gt;When &lt;code&gt;setState&lt;/code&gt; is called, it triggers a render by setting the root of the &lt;code&gt;wip&lt;/code&gt; tree from &lt;code&gt;null&lt;/code&gt; to the root Fiber node. However, the render is not triggered immediately. There is another function that, whenever the browser runs out of high-priority tasks, will check if &lt;code&gt;wip&lt;/code&gt; is null. If &lt;code&gt;wip&lt;/code&gt; is not null, it will actually begin re-rendering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Apply all the actions on state
&lt;/h2&gt;

&lt;p&gt;Functional component are essentially functions that will be run in each render. Every time a functional component is run, all of its &lt;code&gt;useState&lt;/code&gt; will be triggered, which means new hooks and new &lt;code&gt;setState&lt;/code&gt; functions will be created. In addition...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="c1"&gt;// apply all the actions saved from last rendering&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;actions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;oldHook&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;oldHook&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;queue&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="nx"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;hook&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;hook&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All the actions that were saved in the &lt;code&gt;oldHook.queue&lt;/code&gt; in the previous render (remember in the &lt;code&gt;setState&lt;/code&gt; of the previous render where we push the &lt;code&gt;action&lt;/code&gt; into the &lt;code&gt;hook.queue&lt;/code&gt;?) will be applied on the old state to retrieve the new state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final words
&lt;/h2&gt;

&lt;p&gt;And that, folks, is the anatomy of the &lt;code&gt;useState&lt;/code&gt; function. If you want to see how &lt;code&gt;useState&lt;/code&gt; fits into the bigger picture, definitely check out Rodrigo's tutorial.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>React Rendering &amp; Commit phases</title>
      <dc:creator>Quan Phan</dc:creator>
      <pubDate>Sun, 12 Nov 2023 18:50:31 +0000</pubDate>
      <link>https://dev.to/qhphan/build-your-own-react-rendering-commit-phases-1man</link>
      <guid>https://dev.to/qhphan/build-your-own-react-rendering-commit-phases-1man</guid>
      <description>&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;p&gt;This post is part of my post series that complements the &lt;a href="https://pomb.us/build-your-own-react/"&gt;"Build your own React" tutorial by Rodrigo Pombo&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  In this post...
&lt;/h2&gt;

&lt;p&gt;In step 5, Rodrigo introduced the rendering and commit phases, but the distinction and the role of each phase was not clear. Let's change that!&lt;/p&gt;

&lt;h2&gt;
  
  
  What happens when a React program runs?
&lt;/h2&gt;

&lt;p&gt;Remember these first lines in the tutorial?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you have implemented the entire Didact library, the above three lines will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build a new virtual DOM, which is basically a tree whose nodes are elements created from &lt;code&gt;createElement&lt;/code&gt; (line 1).&lt;/li&gt;
&lt;li&gt;Compare the nodes in the virtual DOM with the corresponding fibers in the current fiber tree in the &lt;code&gt;reconcileChildren&lt;/code&gt; function (officially called &lt;code&gt;diffing&lt;/code&gt; by React team). The result of this process is...&lt;/li&gt;
&lt;li&gt;A new Fiber that contains the message denoting to the commit phase what to do with it (&lt;code&gt;effectTag&lt;/code&gt;), and the necessary data to perform that action.&lt;/li&gt;
&lt;li&gt;These fibers are sent to the &lt;code&gt;commitRoot&lt;/code&gt; function to be reflected into the real DOM.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first 3 steps belong to the rendering phase, while the last step is the commit phase. So, the rendering phase includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rendering the virtual DOM&lt;/li&gt;
&lt;li&gt;Reconciliation / Diffing between the wip and current tree&lt;/li&gt;
&lt;li&gt;Preparing data for the commit phase&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Notes on the use of the word "rendering"
&lt;/h2&gt;

&lt;p&gt;If you go on and read more posts about React internals, you will see people abusing the word "rendering". They say:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rendering vs. commit phase (as in Rodrigo's language)&lt;/li&gt;
&lt;li&gt;Rendering the virtual DOM&lt;/li&gt;
&lt;li&gt;Rendering the real DOM (i.e the commit phase)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;... so just be on the look out for that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Notes
&lt;/h2&gt;

&lt;p&gt;Notice how the Fiber is only used in the rendering phase. That means while the browser can temporarily put on hold the rendering phase to work on other high-priority tasks, the commit phase cannot be interrupted.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>React Fiber tree</title>
      <dc:creator>Quan Phan</dc:creator>
      <pubDate>Sun, 12 Nov 2023 18:26:30 +0000</pubDate>
      <link>https://dev.to/qhphan/build-your-own-react-fiber-tree-2kij</link>
      <guid>https://dev.to/qhphan/build-your-own-react-fiber-tree-2kij</guid>
      <description>&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;p&gt;This post is part of my post series that complements the &lt;a href="https://pomb.us/build-your-own-react/"&gt;"Build your own React" tutorial by Rodrigo Pombo&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  In this post...
&lt;/h2&gt;

&lt;p&gt;In step 4, Rodrigo introduced the Fiber architecture. However, he didn't relate Fiber to the bigger picture of React. This post will review what Fiber is, what its purpose is, and how this concept relates to Virtual DOM.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Fiber?
&lt;/h2&gt;

&lt;p&gt;Fiber tree is a tree data structure, where each node is a Fiber. A Fiber is an object that has the following properties:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;DidactElementProps&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;DidactElement&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;DidactElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;DidactElementProps&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Fiber&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;DidactElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Fiber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;sibling&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Fiber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;child&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Fiber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;dom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;HTMLElement&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;alternate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Fiber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;effectTag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What can make Fiber confusing is the fact that the object encompasses so much information. Let's break it down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;(Information of) the virtual DOM: &lt;code&gt;type&lt;/code&gt; and &lt;code&gt;props&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The actual DOM node: &lt;code&gt;dom&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Its connection to the tree: &lt;code&gt;parent&lt;/code&gt;, &lt;code&gt;child&lt;/code&gt;, &lt;code&gt;sibling&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The corresponding fiber in the previous render: &lt;code&gt;alternate&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Message to the commit phase on what to do with this Fiber: &lt;code&gt;effectTag&lt;/code&gt; (update/delete/insert into the DOM)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A Fiber node represents either a DOM node (&lt;code&gt;h1&lt;/code&gt;, &lt;code&gt;div&lt;/code&gt;, &lt;code&gt;p&lt;/code&gt;, etc.) or a function that corresponds to a functional component.&lt;/p&gt;

&lt;h2&gt;
  
  
  Purpose of Fiber tree
&lt;/h2&gt;

&lt;p&gt;It enables us to break down the rendering phase into small units of work, each of which corresponds to a Fiber in the tree. The browser decides the number of work units/fibers it works on before it has to leave the rendering and come back later because it has a higher priority task awaits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fiber and Virtual DOM
&lt;/h2&gt;

&lt;p&gt;In Rodrigo's tutorial, the Fiber tree "acts" as a virtual DOM.&lt;/p&gt;

&lt;p&gt;In the first code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line creates the actual virtual DOM, which is passed into the &lt;code&gt;render&lt;/code&gt; function. Down the line, in &lt;code&gt;reconcileChildren&lt;/code&gt; (in step 5), the &lt;code&gt;type&lt;/code&gt; and &lt;code&gt;props&lt;/code&gt; of each node in the virtual DOM are deconstructed and initiated as the type and props of a fiber.&lt;/p&gt;

&lt;p&gt;Mentally, we can think of it as the Fiber tree is a physical representation of the virtual DOM or the Fiber tree acts as a virtual DOM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deeper read
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/acdlite/react-fiber-architecture"&gt;https://github.com/acdlite/react-fiber-architecture&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Set up environment variables in Jest for your frontend</title>
      <dc:creator>Quan Phan</dc:creator>
      <pubDate>Sun, 12 Nov 2023 16:46:24 +0000</pubDate>
      <link>https://dev.to/qhphan/set-up-environment-variables-in-jest-2lj3</link>
      <guid>https://dev.to/qhphan/set-up-environment-variables-in-jest-2lj3</guid>
      <description>&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;p&gt;Our tests are isolated from the production code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-project/
├── src/
├── test/
├── .env.local
├── package.json
└── ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our production code (in &lt;code&gt;src/&lt;/code&gt;) uses several environment variables imported from &lt;code&gt;.env&lt;/code&gt; or &lt;code&gt;.env.local&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal
&lt;/h2&gt;

&lt;p&gt;We want to test the part of the production code that uses the environment variables in &lt;code&gt;.env.local&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Without proper set up, Jest will not load the environment variables into &lt;code&gt;process.env&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to
&lt;/h2&gt;

&lt;p&gt;Create a JS set up file for Jest. In the JS file, load the environment variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// env.js&lt;/span&gt;
&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;path/to/env/file&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a &lt;code&gt;jest.config.js&lt;/code&gt; file (at the same level as &lt;code&gt;package.json&lt;/code&gt;), and put in there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;// other settings&lt;/span&gt;
   &lt;span class="na"&gt;setupFiles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;rootDir&amp;gt;/path/set/up/file.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Done!&lt;/p&gt;

&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;p&gt;Here is my set up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-project/
├── .jest/
│   └── env.js
├── public/
├── src/
├── test/
├── package.json
├── .env.local
├── jest.config.js
└── ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;jest.config.js&lt;/code&gt;...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;// other settings&lt;/span&gt;
   &lt;span class="na"&gt;setupFiles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;rootDir&amp;gt;/.jest/env.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="c1"&gt;// Keep the &amp;lt;rootDir&amp;gt; as is, DON'T replace it with your root directory&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;.jest/env.js&lt;/code&gt;...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.env.local&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="c1"&gt;// after this line, you can edit any variable in process.env&lt;/span&gt;
&lt;span class="c1"&gt;// to fit the test environment. for example...&lt;/span&gt;
&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ENVIRONMENT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>testing</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Review “Build your own React” by Rodrigo Pombo</title>
      <dc:creator>Quan Phan</dc:creator>
      <pubDate>Sat, 11 Nov 2023 19:34:17 +0000</pubDate>
      <link>https://dev.to/qhphan/review-build-your-own-react-by-rodrigo-pombo-j1h</link>
      <guid>https://dev.to/qhphan/review-build-your-own-react-by-rodrigo-pombo-j1h</guid>
      <description>&lt;p&gt;Brilliant tutorial on how to build React (not an app, the library itself!) from scratch: &lt;a href="https://pomb.us/build-your-own-react/"&gt;https://pomb.us/build-your-own-react/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ever since I transitioned from Vanilla JS to React, I have always wanted to know how React works under the hood - it just seems so magical when the state updates, the entire UI updates accordingly. &lt;/p&gt;

&lt;p&gt;The tutorial taught me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How React works under the hook&lt;/li&gt;
&lt;li&gt;Important concepts in React 16: Fiber tree and Concurrent Mode, Rendering vs. Commit phase, Reconciliation&lt;/li&gt;
&lt;li&gt;Clean code and the importance of typing (more on this later!)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Frankly, it was not an easy read. Here are the reasons why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Just like with any other code-along tutorial, as more complex ideas are introduced and reflected into the code, it is easy to lose track of which function relates to which function.&lt;/li&gt;
&lt;li&gt;The relationships between high-level concepts were’t explained thoroughly. I didn’t know how the Fiber tree relates to the Virtual DOM, and I was clueless on how the rendering, commit, and reconciliation phases are related to each other.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It costs me a few Medium articles, (great) conversations with ChatGPT and hours of staring at the code, trying to reason it out with myself to grasp the big picture. Honestly, I wouldn’t blame the author since the tutorial was geared towards “code along with me” rather than “here are the big concepts and how they relate”. To compensate, I will have some future posts to break down the tutorial and tackle the related high concepts. Stay tuned!&lt;/p&gt;

&lt;p&gt;That said, it is still a brilliant tutorial. Must-read if you want to understand the React internals.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
