<?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: 0ro</title>
    <description>The latest articles on DEV Community by 0ro (@0ro).</description>
    <link>https://dev.to/0ro</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%2F694320%2F2f7223df-68ad-4c2f-9217-05b5fc32bb66.jpeg</url>
      <title>DEV Community: 0ro</title>
      <link>https://dev.to/0ro</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/0ro"/>
    <language>en</language>
    <item>
      <title>Z-Index Trick You Might Not Know 🚀</title>
      <dc:creator>0ro</dc:creator>
      <pubDate>Sun, 03 Dec 2023 16:21:24 +0000</pubDate>
      <link>https://dev.to/0ro/z-index-trick-you-might-not-know-4ih2</link>
      <guid>https://dev.to/0ro/z-index-trick-you-might-not-know-4ih2</guid>
      <description>&lt;p&gt;In one of the projects where I recently worked, we had a pretty trivial task: Add a panel of buttons for our canvas editor. The design in Figma for this panel looked like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1mn7ci2oc60etgqm7puj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1mn7ci2oc60etgqm7puj.png" alt="Figma design"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, there is a canvas in the design, and above it, a panel with buttons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The buttons need to have the same gap between each other.&lt;/li&gt;
&lt;li&gt;And you should be able to draw behind the buttons.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to achieve it?
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Button&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Button&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Button&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"canvas"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So &lt;strong&gt;the first option&lt;/strong&gt; that will satisfy our requirements is to create all buttons, add them position absolute property, then do some math and add &lt;code&gt;left&lt;/code&gt; and &lt;code&gt;top&lt;/code&gt; properties to every button. That's crazy, right? Especially if you have dynamic content inside of your buttons.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is another approach?
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"panel"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Button&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Button&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Button&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"canvas"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let's see the problem from another perspective and try to redefine our task. To make a panel with buttons and make them respect each other, it's better to wrap them in a container. With flex or grid properties, we will have a desirable behavior for its children. Then we need to calculate the position for that container. You can see the result in the next image:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5gx0o9uu2ul0e4809w0q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5gx0o9uu2ul0e4809w0q.png" alt="Panel above canvas"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But what about our second requirement? We already can't draw in space between buttons. Even if we make our wrapper totally transparent, the click will be caught by this panel, and the canvas will not see it.&lt;/p&gt;

&lt;p&gt;Ideally, we need to have something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bus9xiczrbgtyj5m782.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bus9xiczrbgtyj5m782.png" alt="Canvas between panel and buttons"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Is it even possible? To somehow sneak between your sibling (panel) and its children (buttons) and achieve that rendering order?&lt;/p&gt;

&lt;p&gt;Yes, it is. And I'll tell you how.&lt;/p&gt;

&lt;h2&gt;
  
  
  A bit of theory
&lt;/h2&gt;

&lt;p&gt;Let's say we set a position absolute property to our panel element in CSS. What do you think will happen with its rendering order on the page?&lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_without_z-index" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When the z-index property is not specified on any element, elements are stacked in the following order (from bottom to top):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The background and borders of the root element.&lt;/li&gt;
&lt;li&gt;Descendant non-positioned elements, in order of appearance in the HTML.&lt;/li&gt;
&lt;li&gt;Descendant positioned elements, in order of appearance in the HTML.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, because our panel is already a positioned element, it will be on the top of our canvas. If we set &lt;code&gt;position: absolute&lt;/code&gt; to the canvas, then the canvas will be on the top because it appears after the panel element in HTML.&lt;/p&gt;

&lt;p&gt;But what if we set z-index: 1 to our buttons? Logically, it seems that they should start counting their index from their parent (panel) and still be under the canvas, but they will be &lt;strong&gt;on top of the canvas!!!&lt;/strong&gt;, and our initial task is done. &lt;/p&gt;

&lt;p&gt;You can check it here in this &lt;a href="https://codesandbox.io/p/sandbox/vigilant-cdn-2qgwqf?file=%2Fstyles.css%3A16%2C22&amp;amp;layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clpphmk8500063b6l34zn6acq%2522%252C%2522sizes%2522%253A%255B100%252C0%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clpphmk8500023b6lijmanpsz%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clpphmk8500033b6l4700sfc4%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clpphmk8500053b6l418o6o15%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B45.1651840700698%252C54.8348159299302%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clpphmk8500023b6lijmanpsz%2522%253A%257B%2522id%2522%253A%2522clpphmk8500023b6lijmanpsz%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clpphpx5i00023b6rwnyotirw%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522initialSelections%2522%253A%255B%257B%2522startLineNumber%2522%253A16%252C%2522startColumn%2522%253A22%252C%2522endLineNumber%2522%253A16%252C%2522endColumn%2522%253A22%257D%255D%252C%2522filepath%2522%253A%2522%252Fstyles.css%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522id%2522%253A%2522clppjb32f00023b6rzu6sx4jd%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522initialSelections%2522%253A%255B%257B%2522startLineNumber%2522%253A15%252C%2522startColumn%2522%253A7%252C%2522endLineNumber%2522%253A15%252C%2522endColumn%2522%253A7%257D%255D%252C%2522filepath%2522%253A%2522%252Findex.html%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522id%2522%253A%2522clppjjw5j00023b6rb9d8zl1l%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522initialSelections%2522%253A%255B%257B%2522startLineNumber%2522%253A4%252C%2522startColumn%2522%253A22%252C%2522endLineNumber%2522%253A4%252C%2522endColumn%2522%253A22%257D%255D%252C%2522filepath%2522%253A%2522%252Findex.js%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%252C%2522activeTabId%2522%253A%2522clpphpx5i00023b6rwnyotirw%2522%257D%252C%2522clpphmk8500053b6l418o6o15%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clpphmk8500043b6lva20rxer%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522UNASSIGNED_PORT%2522%252C%2522port%2522%253A0%252C%2522path%2522%253A%2522%2522%257D%255D%252C%2522id%2522%253A%2522clpphmk8500053b6l418o6o15%2522%252C%2522activeTabId%2522%253A%2522clpphmk8500043b6lva20rxer%2522%257D%252C%2522clpphmk8500033b6l4700sfc4%2522%253A%257B%2522tabs%2522%253A%255B%255D%252C%2522id%2522%253A%2522clpphmk8500033b6l4700sfc4%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Afalse%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D" rel="noopener noreferrer"&gt;interactive example&lt;/a&gt;&lt;br&gt;
But how does it work?&lt;/p&gt;

&lt;h2&gt;
  
  
  Explanation
&lt;/h2&gt;

&lt;p&gt;The trick is, if you don't set the &lt;code&gt;z-index&lt;/code&gt; property to your position absolute element, this element doesn't create a stacking context. We didn't set &lt;code&gt;z-index&lt;/code&gt; to panel and the ordering of render for our elements can be represented like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

root element // 0
  panel // 1
    button // 3
    button // 4
    button // 5
  canvas // 2


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The number at the line of the element is the order of rendering. The order is defined as preorder depth-first traversal of the rendering tree. Pre-order traversal means:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Traverse the root node&lt;/li&gt;
&lt;li&gt;Traverse sub-trees from left to right&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8kpzrlp4y3oa35q066p6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8kpzrlp4y3oa35q066p6.png" alt="Order tree"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The more detailed information about ordering and stacking context, read in &lt;a href="https://www.w3.org/TR/CSS21/zindex.html" rel="noopener noreferrer"&gt;CSS spec&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion 🚀
&lt;/h2&gt;

&lt;p&gt;In conclusion, understanding the intricacies of z-index and how it interacts with the positioning of elements can lead to clever solutions, as demonstrated in my example. Remember that an element with &lt;code&gt;position: absolute&lt;/code&gt; &lt;strong&gt;without&lt;/strong&gt; &lt;code&gt;z-index&lt;/code&gt; doesn't create a stacking context.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Console.log it</title>
      <dc:creator>0ro</dc:creator>
      <pubDate>Mon, 18 Sep 2023 15:12:48 +0000</pubDate>
      <link>https://dev.to/0ro/consolelog-it-20lg</link>
      <guid>https://dev.to/0ro/consolelog-it-20lg</guid>
      <description>&lt;p&gt;Finding and fixing bugs in your program is a common task for every developer. In this article, I will outline the steps I follow in my daily work to identify and resolve these issues.&lt;/p&gt;

&lt;p&gt;Let's assume that this bug has already been prioritized for you, and you don't need to validate its value for your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Visual Detection
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Prove Bug Reproduction&lt;/strong&gt;: Gather all facts about the bug, including when and how it reproduces. Ensure that the bug is reproducible. It's important to consider that what may seem like a bug could also be a lack of requirements. You might need to implement a new feature to address it. So, before rushing into fixing it, check if it conflicts with the requirements.&lt;/p&gt;

&lt;p&gt;Reproducing the bug can sometimes be a non-trivial task. Bugs can occur in various places, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your code&lt;/li&gt;
&lt;li&gt;Server environment (servers)&lt;/li&gt;
&lt;li&gt;Network problems&lt;/li&gt;
&lt;li&gt;Client environment (browsers, applications, OS)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  History
&lt;/h2&gt;

&lt;p&gt;Once you have confirmed that the bug exists, the next step is to determine when it started to occur. You can either blame the file where the bug is appearing or examine the Git history and files that were changed, which can provide insights into the problem.&lt;/p&gt;

&lt;p&gt;I personally use VSCode along with the GitLens extension. It makes it easy to blame a file line by line and it offers a Commit Graph feature to navigate through your Git history and view changed files.&lt;/p&gt;

&lt;p&gt;Remember that &lt;strong&gt;not only the code&lt;/strong&gt; can be the cause of the bug. Be aware of recent changes in updates of your server environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Google it
&lt;/h2&gt;

&lt;p&gt;Consider searching for solutions online. You can use Google, stack overflow, or even ask questions to AI models like ChatGPT, which sometimes are not quite well for it, so I stopped doing it, but maybe for getting a new idea when you stacked it can be good.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bottom-Up Approach
&lt;/h2&gt;

&lt;p&gt;When dealing with bugs, consider using &lt;code&gt;console.log&lt;/code&gt; or debugging with built-in tools from where the error occurred and work your way up through the reference tree. This helps you understand the code flow and identify issues.&lt;/p&gt;

&lt;p&gt;Note that debugging may not work well for certain scenarios, such as mouse move events, or when you need to track the difference of values between renders. So &lt;code&gt;console.log&lt;/code&gt; can be here only one option.&lt;/p&gt;

&lt;p&gt;Sometimes the bug can occur without throwing any errors. It can be some inconsistent behavior on UI, so try to search by word, or component name for checking the problem. I even had in my projects CSS debug rule like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.debug&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;outline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;red&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;It helped with the visual detection of a component where the bug is occurred.&lt;/p&gt;

&lt;h2&gt;
  
  
  Binary Search
&lt;/h2&gt;

&lt;p&gt;For localizing and isolating the bug, employ a method similar to a binary search used in engineering. This approach helps narrow down the potential sources of the problem.&lt;/p&gt;

&lt;p&gt;Remove dependencies from your code, and check the results, if the bug is still reproduced repeat it again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open-Source Contributions
&lt;/h2&gt;

&lt;p&gt;If the bug is not within your codebase, consider opening an issue in the relevant open-source repository and consider making a pull request to resolve it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ask your teammate
&lt;/h2&gt;

&lt;p&gt;You can stuck with your investigation sometimes, and if you already have done all of the previous steps, go for advice from one of your teammates. Tell him/her about your investigation, what you've already done step by step, what you've found, show some tricky points that you don't quite understand, and ask his/her opinion and ideas about it. Most of the time during your explanation you can find a solution yourself, or you will try to prove the hypotheses of your teammate. If you are not lucky try another teammate and so on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add tests
&lt;/h2&gt;

&lt;p&gt;Having tests in your code is the most important thing on the way do not repeat the same bug in the future. I cannot advise using &lt;strong&gt;TDD&lt;/strong&gt; methodology from the start of your project, but when you are fixing the bug, it is great to use it. Write your test to prove the bug, and then make it green. Writing unit tests for some startups in my opinion doesn't give significant results, and sometimes it is difficult to sell this idea to a business. Instead, consider using e2e testing libraries like Playwright, Cypress, and so on, they give you results immediately, and you will never again repeat this bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  Communication with Managers
&lt;/h2&gt;

&lt;p&gt;Stay in constant communication with your project managers. They are not interested in wasting time, so keep them updated on your progress, share the results, and set reasonable deadlines. Let them make a decision to continue your investigation. If necessary, discuss the possibility of implementing Plan B. Sometimes, reworking a specific part of the product might be more cost-effective than fixing a complex bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I really like finding bugs in the code, especially when you eventually solve them. So here is the short plan for you to fix any bug in your code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reproduce the bug (it is not always the codebase)&lt;/li&gt;
&lt;li&gt;Gather all available information about the history of the bug&lt;/li&gt;
&lt;li&gt;Google by error&lt;/li&gt;
&lt;li&gt;Console.log from bottom to up

&lt;ul&gt;
&lt;li&gt;Binary search&lt;/li&gt;
&lt;li&gt;Time to contribution to open-source&lt;/li&gt;
&lt;li&gt;Ask your team mate (explain it)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Add tests to cover the bug&lt;/li&gt;
&lt;li&gt;Always be in touch with your managers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And remember &lt;em&gt;Catching A Pokémon Is Not About Skill.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NiltaqGG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ijm4uh58h8y113hvtesm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NiltaqGG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ijm4uh58h8y113hvtesm.png" alt="Detective Pikachu" width="584" height="583"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>productivity</category>
      <category>programming</category>
    </item>
    <item>
      <title>The Mentor Dilemma: Finding Your Way in IT 🚀</title>
      <dc:creator>0ro</dc:creator>
      <pubDate>Thu, 14 Sep 2023 17:42:34 +0000</pubDate>
      <link>https://dev.to/0ro/the-mentor-dilemma-finding-your-way-in-it-4hi6</link>
      <guid>https://dev.to/0ro/the-mentor-dilemma-finding-your-way-in-it-4hi6</guid>
      <description>&lt;p&gt;&lt;em&gt;In my 10-year journey in the world of IT, I've never had the privilege of a mentor.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Who is a Mentor?
&lt;/h2&gt;

&lt;p&gt;In my view, a mentor is an expert in a particular field who's eager to share their knowledge, set strategic goals for your development, and ensure you stay on track. They are both an expert and someone who's willing and eager to mentor. Since they're already established professionals, their time is precious, making it quite rare to encounter such a gem casually.&lt;/p&gt;

&lt;p&gt;So, where can you find one? In many companies, the practice of assigning a more experienced developer within your team or a team lead as a mentor is common. You interact with them through work, they conduct code reviews, and occasionally, they mentor you. However, finding someone truly motivated to share their knowledge and nurture your growth is not an everyday occurrence. Unfortunately, luck hasn't favored me in this regard.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Easier Path with a Mentor
&lt;/h2&gt;

&lt;p&gt;Yes, having a good mentor can save you a ton of time in mastering your craft. They can offer guidance, help you do not step on the wrong path, set the direction for your growth, and ensure you don't miss the essentials. If you find a mentor in your circle, hold onto him/her tightly; you're incredibly fortunate.&lt;/p&gt;

&lt;p&gt;As I mentioned at the beginning of this article, I never had a mentor, at least not as a dedicated individual. Instead, I consumed all available information, attempting to sort and comprehend it on my own. I scoured technical websites, followed all popular bloggers on YouTube and Twitter, listened to podcasts, and watched conference videos available online. This path was entirely unsystematic, undoubtedly taking more time than it would have with a living, breathing mentor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Becoming a Mentor Yourself?
&lt;/h2&gt;

&lt;p&gt;At one point in my career, I became a mentor to a couple of people. Let me share one of those experiences.&lt;/p&gt;

&lt;p&gt;A colleague at work asked for help in teaching one of his friend HTML and CSS. I had never done this before, but I agreed to assist. I crafted a plan, found a suitable design (back when it was still in Photoshop), monitored their progress, organized calls, explained what I would do, what else they needed to learn in parallel, and addressed all their questions. In essence, I tried to be the mentor I had always wanted. Sadly, a couple of weeks later, my mentee disappeared, leaving the project unfinished. This unfair, right? Nevertheless, I took many valuable lessons from this and other experiences, which helped me organize my own knowledge and learn how to interact more effectively. The &lt;strong&gt;"do as I do"&lt;/strong&gt; method yields quick results but isn't sustainable over the long run. On the other hand, an educational approach based on &lt;strong&gt;open-ended questions&lt;/strong&gt;—why? how?—sparks curiosity and transforms learning into an exciting journey.&lt;/p&gt;

&lt;p&gt;Being a mentor is beneficial; it allows you to look at the familiar from a different perspective, enhancing your understanding of the subject.&lt;/p&gt;

&lt;h2&gt;
  
  
  You Don't Need a Mentor
&lt;/h2&gt;

&lt;p&gt;Mentors are fantastic, but if you don't have one, don't despair. The programming field is all about continuous learning and seeking the right information. It's better to learn to navigate this journey on your own from the beginning. We learn best from our own mistakes, so make them and draw conclusions. If you feel the YouTube content isn't sufficient, and you're accustomed to more structured information like in university, you can always find a program for the course you're interested in, like &lt;a href="http://catalog.mit.edu/degree-charts/computer-science-engineering-course-6-3/"&gt;MIT&lt;/a&gt;, and then search for videos on individual topics sequentially, for instance, &lt;a href="https://www.youtube.com/results?search_query=6.1020+mit"&gt;6.1020 mit&lt;/a&gt;. Codes may have changed by now; previously, this course was labeled as 6.006, but finding the topic by name shouldn't be a challenge. Lectures from one of the world's top institutions are at your disposal; you just need to find the time to watch them and dissect them thoroughly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;So, remember, while mentors are invaluable, your thirst for knowledge and determination can carry you far in the realm of programming.&lt;/p&gt;

&lt;p&gt;Whether you have a mentor or not, your journey in IT is defined by only your curiosity, dedication, and the willingness to learn from both successes and failures.&lt;/p&gt;

</description>
      <category>career</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🤔 How I Choose Fabric.js Again</title>
      <dc:creator>0ro</dc:creator>
      <pubDate>Sun, 03 Sep 2023 16:48:46 +0000</pubDate>
      <link>https://dev.to/0ro/how-i-choose-fabricjs-again-41jn</link>
      <guid>https://dev.to/0ro/how-i-choose-fabricjs-again-41jn</guid>
      <description>&lt;p&gt;If you don't know, Fabric.js is the library that helps you manipulate canvas elements in the browser and even on Node.js servers. It is very popular and has more than 25.7k stars on GitHub (one of them from me). But is it still the best option for you? Let's find out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we need libraries?
&lt;/h2&gt;

&lt;p&gt;I can advise using canvas libraries, and even &lt;strong&gt;any library&lt;/strong&gt;, in two main cases:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When you create something simple.&lt;/li&gt;
&lt;li&gt;When you create something that is very complicated.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7w7px25s07ly9mghewu9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7w7px25s07ly9mghewu9.png" alt="normal distribution"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you try to create something that is &lt;strong&gt;simple&lt;/strong&gt;, you usually don't need to use any libraries at all. In our case, you can start with the native built-in Canvas API for browsers or use the &lt;a href="https://www.npmjs.com/package/canvas" rel="noopener noreferrer"&gt;canvas&lt;/a&gt; npm package, which allows you to use the same API on the Node.js environment.&lt;/p&gt;

&lt;p&gt;This option is also valid if you want to learn something new, like Server Sent Events, Websockets, or the Canvas API. Starting with learning a library's API before the native API is always a bad idea. From a long-term perspective, it puts you in a losing situation. It's similar to learning JQuery before JavaScript or React.js before JavaScript. It will be difficult for you to sell your expertise in the future and help you with onboarding in any new library.&lt;/p&gt;

&lt;p&gt;When you create something that is &lt;strong&gt;complicated&lt;/strong&gt;, use the native API. This case is valid if you're trying to create something like Figma, Excalidraw, Miro, or something else that requires a new approach to working with graphics on the web. From a business perspective, it will be much easier and even cheaper to create your own library that is definitely based on the native Canvas API and covers your internal demand. Open-source libraries are sometimes not very customizable.&lt;/p&gt;

&lt;p&gt;So, both cases favor the native API. For projects in the middle, you &lt;strong&gt;can&lt;/strong&gt; use the built-in API too, but it will probably cost you a lot of resources. I'm sure everyone remembers that bad feeling when one day you decided to create your own Select, Datepicker, or Checkbox on a commercial project, and something went wrong with them because you didn't figure out how many edge cases you needed to cover in your code. The same applies here: if you're working on a commercial project and your task is not very simple, first consider using an open-source library. Only if you didn't find something that is really needed for your project should you then switch to a hand-made solution (or take the opportunity to create your own open-source package because you've found something that doesn't exist).&lt;/p&gt;

&lt;p&gt;Defining the simplicity of your task or project is up to you. It is a subjective term, of course, and it depends on your experience. You can expedite gaining experience faster by reading articles and watching videos about programming. People are sharing their experience for free; please use it.&lt;/p&gt;

&lt;p&gt;This is a fundamental concept that everyone should know. Let's continue.&lt;/p&gt;

&lt;h2&gt;
  
  
  My first time with Fabric.js
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjx9owpw32lhu4fjz4gb6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjx9owpw32lhu4fjz4gb6.png" alt="First time"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It wasn't like on the picture; it wasn't comparable to hanging, but it wasn't a great time for me. Because I made that mistake, I started learning the Fabric.js API before I was very familiar with all the concepts of the native canvas API. But, to be fair, Fabric.js is very friendly for geniuses like me. I almost never touched the canvas API on that project because everything was already implemented in Fabric.js. It's good for a library, right? And, of course, during the investigation of some bugs, I learned the Canvas API anyway because if you think you can avoid something, fate will surely punish you.&lt;/p&gt;

&lt;h2&gt;
  
  
  High-level architecture
&lt;/h2&gt;

&lt;p&gt;So, after 7 years, I needed a library again for creating a graphic editor. One of the requirements was a Canvas-based approach. So, of course, I considered using Fabric.js because I was already very familiar with it. But I wanted to discover the current state of affairs in the world of Canvas-based libraries on the web and check the state of Fabric.js.&lt;/p&gt;

&lt;p&gt;First of all, don't even think about libraries that are bound to some popular frontend framework like React.js, Vue.js, and others. You don't need them because you will still use only &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; there and somehow connect it to your desired canvas library. The high-level architecture for such an editor can look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F47tj7l9jkplyp2tzu3w1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F47tj7l9jkplyp2tzu3w1.png" alt="High-level arch diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From left to right, you can see:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Frontend framework, it can be anything you use, React.js, Vue.js, and others, or you can even avoid using frameworks altogether.&lt;/li&gt;
&lt;li&gt;Editor component. A component where you're going to store your canvas tag, and where you are going through your state management to initialize your library.&lt;/li&gt;
&lt;li&gt;State management. Here, you can use anything you want to sync the canvas state with your component state. It can be Zustand, MobX, Jotai, or even Redux.&lt;/li&gt;
&lt;li&gt;Adapter is going to store the methods and properties that you will use to describe the logic for your Canvas Library and customize the standard behavior of that library.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, we can focus on finding the Canvas-based library.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some libraries are dead
&lt;/h2&gt;

&lt;p&gt;There are a lot of libraries that work with the Canvas API, and I would divide them into two big groups:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visualization libraries.&lt;/li&gt;
&lt;li&gt;Whiteboard/drawing libraries.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Visualization libraries are the ones that help you with visualizing your data on canvas or animating it to make it more like a game. So, they are not my case.&lt;/p&gt;

&lt;p&gt;Whiteboard/drawing libraries are what I'm looking for to create my graphic editor.&lt;/p&gt;

&lt;p&gt;I don't have all the time in the world to check and try each library because the real development experience of working with a library is the most important and valuable. Only when you create something using a library you see its problems and limitations. So, as I said, I don't have time. Instead of creating a proof of concept with every library, I tried to find all the candidates and make a decision based on these points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open-source&lt;/li&gt;
&lt;li&gt;GitHub stars&lt;/li&gt;
&lt;li&gt;NPM downloads&lt;/li&gt;
&lt;li&gt;Stack Overflow questions&lt;/li&gt;
&lt;li&gt;Date of the last release&lt;/li&gt;
&lt;li&gt;Documentation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Based on this, I found that some of the libraries are dead and no longer have any support. Only two libraries are still alive and have significant amount of stars on GitHub and downloads on NPM. They are &lt;a href="https://github.com/fabricjs/fabric.js" rel="noopener noreferrer"&gt;Fabric.js&lt;/a&gt; and &lt;a href="https://github.com/konvajs/konva" rel="noopener noreferrer"&gt;Konva.js&lt;/a&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Fabric.js&lt;/th&gt;
&lt;th&gt;Konva.js&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;GitHub stars&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;25.7k&lt;/td&gt;
&lt;td&gt;9.7k&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;NPM downloads&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;140,574&lt;/td&gt;
&lt;td&gt;276,004&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Stack Overflow questions&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;9,806&lt;/td&gt;
&lt;td&gt;986&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Date of the last release&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;2 weeks ago&lt;/td&gt;
&lt;td&gt;3 months ago&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Documentation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Good&lt;/td&gt;
&lt;td&gt;Good&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;As you can see, Fabric.js is dominating in all metrics. The most interesting moment is that they are preparing a new release with a lot of new features, which is a very good sign because it means that the library is still alive and has a lot of contributors.&lt;/p&gt;

&lt;p&gt;I would really like to try Konva.js too, but I don't have time for it, and I'm not sure that it will be better than Fabric.js. So, I decided to use Fabric.js, and after a few months of active usage I have no regrets about it.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>canvas</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Nobody knows how to estimate software projects</title>
      <dc:creator>0ro</dc:creator>
      <pubDate>Fri, 01 Sep 2023 18:31:39 +0000</pubDate>
      <link>https://dev.to/0ro/nobody-knows-how-to-estimate-software-projects-2c94</link>
      <guid>https://dev.to/0ro/nobody-knows-how-to-estimate-software-projects-2c94</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclaimer. This article is a joke. Only me and God know how to estimate software projects. And I am not sure about God.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Great Unknown
&lt;/h2&gt;

&lt;p&gt;Let's imagine you are a Tech Lead, and recently you were asked to estimate a software project. You were given a list of features and asked to estimate how long it would take to implement each feature and the entire project. You were given a couple of days for it...&lt;/p&gt;

&lt;p&gt;A couple of days! Really? Estimate the entire project. It cannot be enough. Even for the best of us. Even if you have done it before many times. But how much time do you need? A week? A month? It always will not be precise anyway. So, maybe a couple of days is a good option, at least you will not waste a lot of time on it.&lt;/p&gt;

&lt;p&gt;And be sure, your managers will tell you, "Don't worry, no need to dive deep into details, we just need a rough estimate and nothing more, you will manage to do it, come on buddy".&lt;/p&gt;

&lt;p&gt;And of course, they lie. They will use your estimation to plan the project, to plan the budget, to plan the team, to plan the deadlines, to plan the marketing, to plan the sales, and to plan the future of the company. And they will use it to blame you later when you will not be able to deliver the project on time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvokami4cfq865dahoil.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvokami4cfq865dahoil.png" alt="HA-HA-HA"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Burden of Responsibility
&lt;/h2&gt;

&lt;p&gt;The customer needs to know how much it will cost to implement the project. It is a good reason, right? They need to prepare money for their amazing start-up, or maybe find investors, who will pay for it. And the amount of money they will ask depends on you. So, it is a big responsibility, including the fact that only you know how you came up with the numbers.&lt;/p&gt;

&lt;p&gt;Usually, customers ask for estimates from several companies, and then they will choose someone. It is not always the cheapest one, there are a lot of factors that influence the decision, but the price is one of the most important factors. And here is the catch:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On your side&lt;/strong&gt;, if you will give a price that is too high, for the customer, you will usually lose because the project is not on you. If you give a price that is too low, you will usually win the battlefield, but you will lose this war later, when you are working on the project every night.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On the customer side&lt;/strong&gt;, if you provide them with a budget that is too low, they will not be able to implement the project, and they will lose. If you provide them with a budget that is too high, they will lose, because they will not be able to find investors.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Illusion of Technique
&lt;/h2&gt;

&lt;p&gt;So, how to estimate the project? There are a lot of techniques and maybe you know some of them. There are countless methods: expert judgment, story points, bottom-up estimate, three-point estimating - you name it. They all promise to unveil the magic number. But guess what? None of them have the Midas touch.&lt;/p&gt;

&lt;p&gt;You might meticulously break down the project into user stories, assign story points, and create impressive Gantt charts. You might consult with your team and reach a consensus. You might even throw in some past project data for good measure. Yet, when the &lt;strong&gt;deadline day&lt;/strong&gt; arrives, you're either ahead of schedule with nothing left to do or drowning in an ocean of bugs and scope changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In the wild world of software project estimation, one thing is clear: it's &lt;strong&gt;an art&lt;/strong&gt;, not a science. It's a complex dance of uncertainty, expectations, and a dash of wishful thinking. So, next time you're asked to estimate a software project, remember to take it all with a grain of humor and a pinch of humility. After all, in the ever-evolving realm of software development, the only constant is &lt;strong&gt;the unpredictability of estimation.&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>management</category>
      <category>productivity</category>
      <category>estimation</category>
    </item>
    <item>
      <title>📜 Length of String in TypeScript</title>
      <dc:creator>0ro</dc:creator>
      <pubDate>Thu, 31 Aug 2023 18:06:19 +0000</pubDate>
      <link>https://dev.to/0ro/length-of-string-in-typescript-4p15</link>
      <guid>https://dev.to/0ro/length-of-string-in-typescript-4p15</guid>
      <description>&lt;p&gt;I'm very like typescript and I always try to learn something interesting there. I thought that it is &lt;strong&gt;impossible&lt;/strong&gt; to know the length of the string in typescript, but I was wrong. Today during solving typescript challenge I found a way to do it. If you don't know about typescript challenges, you can read about it &lt;a href="https://github.com/type-challenges/type-challenges"&gt;here&lt;/a&gt;, it is a very interesting project, and I highly recommend you to try it, if you, like me, obsessed with typescript.&lt;/p&gt;

&lt;p&gt;Let's start with example where in real life it can be useful. Imagine you have a function for getting a country by its code, and you want that function to accept only strings with length 2. It will be nice to have something like this:&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getCountryByCode&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;string&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;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;isLength&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;&amp;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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Belarus&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;span class="nx"&gt;getCountryByCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;BY&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Belarus"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above we declared a generic type &lt;code&gt;T&lt;/code&gt; which extends &lt;code&gt;string&lt;/code&gt; and we want to check that the length of this string is equal to 2. Unfortunately, typescript doesn't have a built-in type for getting the length of the string, but if it had, it would look like this:&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="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;IsLength&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;
  &lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;N&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Length&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;N&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see here that I declared a generic type that accepts two parameters, and then I'm using the &lt;code&gt;Length&lt;/code&gt; type to get the length of the string and compare it with the second parameter via &lt;code&gt;extends&lt;/code&gt; keyword.&lt;/p&gt;

&lt;p&gt;But &lt;code&gt;Length&lt;/code&gt; type doesn't exist in typescript, so we need to create it by ourselves. There is a trick that allows us to do it. We can use the &lt;code&gt;infer&lt;/code&gt; keyword to get the length of the string. If you don't know how infer keyword works in Typescript I can recommend you my article about it &lt;a href="https://0ro.github.io/posts/infer-keyword-in-typescript/"&gt;here&lt;/a&gt;. So let's create our &lt;code&gt;Length&lt;/code&gt; type:&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="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;StringToTuple&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;infer&lt;/span&gt; &lt;span class="nx"&gt;Char&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nx"&gt;infer&lt;/span&gt; &lt;span class="nx"&gt;Rest&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;Char&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;StringToTuple&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Rest&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&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="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Length&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nx"&gt;StringToTuple&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt;&lt;span class="o"&gt;&amp;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;length&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;It's crazy, right? But let me explain how it works.&lt;/p&gt;

&lt;p&gt;First of all, we need to convert our string to tuple, and we can do it with the &lt;code&gt;StringToTuple&lt;/code&gt; type. It accepts a generic type &lt;code&gt;S&lt;/code&gt; which extends &lt;code&gt;string&lt;/code&gt; and then we are using the &lt;code&gt;infer&lt;/code&gt; keyword inside the template literal type, that allows us to get the first character of the string and the rest of the string. Then we use the spread operator to add the first character to the tuple and call the &lt;code&gt;StringToTuple&lt;/code&gt; type again with the rest of the string. We are doing it until the string is empty, and then we return an empty array.&lt;/p&gt;

&lt;p&gt;It means that if we have a string like &lt;code&gt;"BY"&lt;/code&gt; it will be converted to the tuple &lt;code&gt;["B", "Y"]&lt;/code&gt;. And then we can get the length of the tuple with the &lt;code&gt;Length&lt;/code&gt; type, it is possible because the tuple type knows exactly how many elements it has. You can read more about tuples &lt;a href="https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So, the full way to get the length of the string will look like this:&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="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;StringToTuple&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;infer&lt;/span&gt; &lt;span class="nx"&gt;Char&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nx"&gt;infer&lt;/span&gt; &lt;span class="nx"&gt;Rest&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;Char&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;StringToTuple&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Rest&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&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="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Length&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;StringToTuple&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt;&lt;span class="o"&gt;&amp;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;length&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;IsLength&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;
  &lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;N&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Length&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;N&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, but I'm not done yet, based on this we already can create more utility types:&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="c1"&gt;// check if string is empty&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;IsEmpty&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;IsLength&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// check if string is not empty&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;IsNotEmpty&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;IsLength&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;
  &lt;span class="nx"&gt;S&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// check if string is shorter than N&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;IsShorter&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;
  &lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;N&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;IsLength&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// check if string is longer than N&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;IsLonger&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;
  &lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;N&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;IsLength&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Honestly I don't know we're it can be useful, but it is possible to do it, and it is cool. 😎&lt;/p&gt;

&lt;p&gt;On my projects I have a special place for my utility types. It is pretty handy and I always can hope that they will be useful in the future. So, I added this types to my utility types, and I hope that they will be useful for you too.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this article, and if you have any questions or suggestions, please feel free to ask.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Enabling Dark Mode in React.js with SCSS Modules 🌙</title>
      <dc:creator>0ro</dc:creator>
      <pubDate>Tue, 29 Aug 2023 09:38:04 +0000</pubDate>
      <link>https://dev.to/0ro/enabling-dark-mode-in-reactjs-with-scss-modules-2mm0</link>
      <guid>https://dev.to/0ro/enabling-dark-mode-in-reactjs-with-scss-modules-2mm0</guid>
      <description>&lt;p&gt;In one of my recent projects, I needed to add support for dark mode to a React.js Single Page Application (SPA). Since we were using SCSS modules to style our elements, let's explore how to implement dark mode in a React.js project with SCSS modules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Switching Color Schemes
&lt;/h2&gt;

&lt;p&gt;With widespread browser support for &lt;a href="https://caniuse.com/css-variables"&gt;CSS variables&lt;/a&gt;, I don't see any alternative to using the &lt;strong&gt;body class + CSS variables&lt;/strong&gt; approach. This means that when a user enables dark mode in your application, a &lt;code&gt;.dark&lt;/code&gt; class is added to the &lt;code&gt;body&lt;/code&gt; tag, and the variables are overridden based on the presence or absence of this class.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Variables
&lt;/h2&gt;

&lt;p&gt;If you're not already familiar, &lt;strong&gt;CSS variables (custom properties)&lt;/strong&gt; are entities in CSS that allow you to store values and then use them in your styles. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#ccc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// define a CSS variable&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;text-color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// get a variable&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;text-color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// get a variable&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Variable names should always start with a double hyphen (--), and you access a variable by using the &lt;strong&gt;var()&lt;/strong&gt; function.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;var()&lt;/strong&gt; function will attempt to find the &lt;strong&gt;--text-color&lt;/strong&gt; variable within its scope or from its parents. In our case, that's the body. However, you can redefine this variable so that, for example, &lt;strong&gt;h1&lt;/strong&gt; and &lt;strong&gt;p&lt;/strong&gt; elements inside sections have a different color:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nt"&gt;section&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#ddd&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our case, this trick will help override variables for dark mode.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real case
&lt;/h2&gt;

&lt;p&gt;First, declare all the variables your designers use in layouts on the &lt;strong&gt;:roo&lt;/strong&gt;t pseudo-class and add them to a &lt;strong&gt;global.scss&lt;/strong&gt; file in your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;--black&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="na"&gt;--gray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#ccc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="na"&gt;--white&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="na"&gt;--blue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#0085f2&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;In this case, I suggest not tying variable names to the entities where you plan to use them. For instance, don't name them like &lt;strong&gt;--text-primary-color: #ccc&lt;/strong&gt;, because we're going to define this at the level of React component styles. For example, you have a  component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;classNames&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;classnames&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Text.module.scss&lt;/span&gt;&lt;span class="dl"&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;ITextProps&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;primary&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;secondary&lt;/span&gt;&lt;span class="dl"&gt;"&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ReactNode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FC&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ITextProps&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;primary&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;children&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;classNames&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;Type`&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;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;As you can see, this is a simple React Component that can have one of two types, which we intend to handle in the style file.&lt;/p&gt;

&lt;p&gt;The style file (Text.module.scss) for this component will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nc"&gt;.primaryType&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;text-color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.secondaryType&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;text-color&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;Here, for each text type, I've defined my own variable whose value is taken from the &lt;strong&gt;:root&lt;/strong&gt; pseudo-class.&lt;/p&gt;

&lt;p&gt;Now, to enable dark mode for text, we need to use the &lt;strong&gt;body.dark&lt;/strong&gt; class. We can do this as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nc"&gt;.primaryType&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;text-color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.secondaryType&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;text-color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;:global&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;.dark&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.primaryType&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="no"&gt;gray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nc"&gt;.secondaryType&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="no"&gt;white&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;:global(.dark)&lt;/strong&gt; allows us to use global SCSS modules classes. Here, we simply override variable values, which, due to the nesting within the &lt;strong&gt;.dark&lt;/strong&gt; class, will take higher priority than the ones declared above.&lt;/p&gt;

&lt;p&gt;Since we are using SCSS, we can create a &lt;strong&gt;mixin&lt;/strong&gt; based on this approach. Let's also add a media query to apply dark mode based on the user's operating system settings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XpEq9m8---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xcrx5cnu3qsq2j1pxml6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XpEq9m8---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xcrx5cnu3qsq2j1pxml6.png" alt="Mac OS theme change" width="457" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's what the mixin will look like:&lt;/p&gt;

&lt;h2&gt;
  
  
  SCSS Mixin
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;dark-mode&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefers-color-scheme&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;dark&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;@content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nd"&gt;:global&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;.dark&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;@content&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's how you can use this mixin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s2"&gt;"../styles/mixins"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;.primaryType&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;text-color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.secondaryType&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;text-color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;dark-mode&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.primaryType&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="no"&gt;gray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nc"&gt;.secondaryType&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="no"&gt;white&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, dark mode styles for your components will be isolated and conveniently located at the end of the file, making it easy to navigate through them. 🌙&lt;/p&gt;

</description>
      <category>react</category>
      <category>scss</category>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>🚀 How would I start a React project now? 🤓</title>
      <dc:creator>0ro</dc:creator>
      <pubDate>Sat, 26 Aug 2023 19:04:55 +0000</pubDate>
      <link>https://dev.to/0ro/dominate-react-project-startups-insider-tips-for-dev-success-4c21</link>
      <guid>https://dev.to/0ro/dominate-react-project-startups-insider-tips-for-dev-success-4c21</guid>
      <description>&lt;p&gt;I work at an outsourcing company, and we often have to create projects from scratch. Every time before starting this process, I try to conduct research on what needs to be chosen. Since I have more experience in the React ecosystem, in this article, I would like to answer the question: how would I start a React project now? 🤔&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; The following article reflects my personal opinions and experiences. Please consider project-specific factors and team expertise when making technology choices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gathering Requirements 📝
&lt;/h2&gt;

&lt;p&gt;Let's imagine that you, like me, are a developer at an outsourcing company or a freelancer, and you have received an order to create a new project. You need to work on the frontend part. Where should you start, and how should you approach choosing a framework? 🧐&lt;/p&gt;

&lt;h3&gt;
  
  
  What to Ask? 🤷‍♂️
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Which browsers need to be supported? 🌐&lt;/li&gt;
&lt;li&gt;Which devices need to be supported? (mobile, tablets, desktop) 📱💻&lt;/li&gt;
&lt;li&gt;Language support? 🌎&lt;/li&gt;
&lt;li&gt;Do you have any design or mockups? The choice of framework depends on this. 🎨&lt;/li&gt;
&lt;li&gt;Dark theme? 🌙&lt;/li&gt;
&lt;li&gt;Is there a backend? 🌐&lt;/li&gt;
&lt;li&gt;Do you need server-side rendering? This is important for SEO. 🚀&lt;/li&gt;
&lt;li&gt;Tests? 🧪&lt;/li&gt;
&lt;li&gt;Are there any special integrations with other services or APIs? 🤝&lt;/li&gt;
&lt;li&gt;Accessibility? ♿&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These questions apply to &lt;strong&gt;any&lt;/strong&gt; project. This forms the foundation, and from these answers, you can build a dialogue with the client. However, the functional requirements for all applications are different. They will determine the internal content of your project and the architecture of the system's internal parts. For example, if it's a banking application, it will involve many forms, whereas if it's a shopping app, it will have many product cards. If it's a graphic editor, you'll need to think about choosing a library for working with graphics, and so on. In general, gather as much information as possible about the project. 📊&lt;/p&gt;

&lt;h3&gt;
  
  
  Common Requirements 📦
&lt;/h3&gt;

&lt;p&gt;Functional requirements differ, but the skeleton of the application is usually the same. Here's an approximate list of what needs to be done in any project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8rizc36pabdg3jm6ypvh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8rizc36pabdg3jm6ypvh.png" alt="Application parts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication/Global state ✅&lt;/li&gt;
&lt;li&gt;Routing 🚏&lt;/li&gt;
&lt;li&gt;State management 📂&lt;/li&gt;
&lt;li&gt;UI components 💎&lt;/li&gt;
&lt;li&gt;i18n (internationalization) 🌍&lt;/li&gt;
&lt;li&gt;Styling 🎨&lt;/li&gt;
&lt;li&gt;Linting, formatting 🧹&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is where it gets interesting for me. What tools should you choose for each of these points? 🛠️&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2qupooy5ipecmjv8zkfx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2qupooy5ipecmjv8zkfx.png" alt="Hard to choose"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Frameworks 🛡️
&lt;/h2&gt;

&lt;p&gt;Every time, I start this story from scratch and try to make a fresh decision about the framework.&lt;/p&gt;

&lt;p&gt;It's worth mentioning that the choice of framework depends on your team's experience and your own. If you and your team haven't worked on React.js projects before, starting a new project for which you're being paid can be a risky endeavor. If you value your client's money and your reputation, it's better to develop in something you already know well. Save experimentation for your own projects. 💼💡&lt;/p&gt;

&lt;p&gt;In my case, I have experience with &lt;strong&gt;create-react-app&lt;/strong&gt; and &lt;strong&gt;Vite + React.js&lt;/strong&gt;, and unfortunately I've never had a chance for working with &lt;strong&gt;Next.js&lt;/strong&gt;. 📚🔍&lt;/p&gt;

&lt;p&gt;It seems obvious to everyone that Vite has won in this showdown. But I wouldn't completely dismiss &lt;strong&gt;create-react-app&lt;/strong&gt;, and here's why. 🥊&lt;/p&gt;

&lt;h3&gt;
  
  
  Create-react-app? 🎉
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdcbv8at0wt5ivajqwx4k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdcbv8at0wt5ivajqwx4k.png" alt="CRA"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my most recent project, I needed to build an application with micro-frontends. Starting my research in this area, I found that the Vite plugin for supporting Module Federation is not stable. In particular, I faced an &lt;a href="https://github.com/originjs/vite-plugin-federation/issues/294" rel="noopener noreferrer"&gt;issue&lt;/a&gt; that is still open, raising doubts about its usage. Meanwhile, &lt;strong&gt;create-react-app&lt;/strong&gt; works with Module Federation without any issues. I had to make this difficult decision back then, endure the slow webpack build in favor of stability. 😓&lt;/p&gt;

&lt;p&gt;So, at this stage, if you need Module Federation support, it's better to go with &lt;strong&gt;create-react-app + craco&lt;/strong&gt;. Yes, Next.js also has support for Module Federation, as far as I know, there's a paid plugin for it, but why use Next.js for lightweight micro-frontends? Micro-frontends are always about customization and flexibility, while Next.js is more of a monolithic framework. Additionally, &lt;a href="https://www.rspack.dev/" rel="noopener noreferrer"&gt;rspack&lt;/a&gt; looks promising, theoretically allowing migration from webpack when Module Federation is ready there. 🏗️&lt;/p&gt;

&lt;h3&gt;
  
  
  Next.js? 🌐
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsywfnj3i60idpktqkx4o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsywfnj3i60idpktqkx4o.png" alt="Next.js"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next.js&lt;/strong&gt; is an excellent framework. I always want to start a project with it because it's at the forefront of the React.js ecosystem, and it's satisfying to stay up-to-date. I've identified a few cases where I would choose Next.js for my projects:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;SEO. 📈&lt;/li&gt;
&lt;li&gt;Small backend 🌐&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If your site is a sales page, a portfolio page, or something similar where SEO is crucial, then choosing Next.js seems justified. Also, if your backend isn't too complex, and you don't need a lot of server-side logic, which is generally suitable for portfolio sites, then Next.js can be a good choice. In other cases, I would consider different options.&lt;/p&gt;

&lt;p&gt;For me, at this moment, the server in Next.js is a backend for frontend developers. In other words, it's suitable for something simple, but if you have complex business logic, you'll reach a point where you need a separate backend, and then all the advantages of Next.js will disappear. Especially when nowadays everyone goes to serverless backend on lambda functions. 🦄&lt;/p&gt;

&lt;h3&gt;
  
  
  Vite + React.js? 🚀
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fua9pomijmoef1pdoigup.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fua9pomijmoef1pdoigup.png" alt="Vite"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vite + React.js&lt;/strong&gt; is currently a good compromise for starting a new project. The community around Vite continues to grow, and most likely, all the typical problems you'll face during development have already been solved. You can enjoy fast builds and hot reload. The only drawback at the moment is Module Federation, as I mentioned in the create-react-app section. 🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  State Management 🧠
&lt;/h2&gt;

&lt;p&gt;It's worth mentioning that state management needs to be divided into two parts: Server state management and Client state management. In my current applications, I separate these two concepts and use different tools for them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxf2g6gz2xvbo4yeqc3dy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxf2g6gz2xvbo4yeqc3dy.png" alt="State management"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Server state management
&lt;/h3&gt;

&lt;p&gt;When choosing a tool for Server state management, you need to consider what you're using on the backend. For GraphQL, Apollo is suitable, and for REST API, there are several options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://redux-toolkit.js.org/rtk-query/overview" rel="noopener noreferrer"&gt;RTK Query&lt;/a&gt; 🚀&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://swr.vercel.app/" rel="noopener noreferrer"&gt;SWR&lt;/a&gt; 🕸️&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tanstack.com/query/latest/" rel="noopener noreferrer"&gt;react-query&lt;/a&gt; ⚛️&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The react-query website even has a &lt;a href="https://tanstack.com/query/v4/docs/react/comparison" rel="noopener noreferrer"&gt;comparison table&lt;/a&gt; of these tools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fil3tnf1mowjv1i3a5paz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fil3tnf1mowjv1i3a5paz.png" alt="Comparison Table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my projects, I've long abandoned Redux, so I'm not inclined to choose &lt;strong&gt;RTK-query&lt;/strong&gt;. Right now, I would choose &lt;strong&gt;react-query&lt;/strong&gt; for my project because it offers more features than SWR. I make this choice to avoid risks in the future since this layer of the application is usually challenging to change during development. 🧐&lt;/p&gt;

&lt;h3&gt;
  
  
  Client state management
&lt;/h3&gt;

&lt;p&gt;For client state management, you need to choose the most suitable tool for the specific situation. Just think about how many questions regarding state management &lt;strong&gt;react-query&lt;/strong&gt; has already answered for you. Data loading, loading states, and more are already handled. This means you only need to handle interactivity and UI element behavior, which are not usually very complex in most applications. Native React.js solutions will work in most places. However, if you need to solve more complex tasks, like a code editor with many states and actions, you'll need to choose a tool that helps manage those states. Here's a list of tools I would consider:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://zustand-demo.pmnd.rs/" rel="noopener noreferrer"&gt;Zustand&lt;/a&gt; 🏗️&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://jotai.org/" rel="noopener noreferrer"&gt;Jotai&lt;/a&gt; 🧙‍♂️&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://recoiljs.org/" rel="noopener noreferrer"&gt;Recoil&lt;/a&gt; 🌀&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since my requirements for client state management are not very complex, I would choose &lt;strong&gt;Zustand&lt;/strong&gt;. It has a simple API and is suitable for most of my tasks. However, there's no problem using different approaches in different parts of the application. For example, using Zustand in one part and even &lt;a href="https://mobx.js.org/README.html" rel="noopener noreferrer"&gt;MobX&lt;/a&gt; in another. 🔄&lt;/p&gt;

&lt;h2&gt;
  
  
  UI Components 🎨
&lt;/h2&gt;

&lt;p&gt;When choosing a library for working with UI components, you should always start with design layouts and requirements. If you have a design, choose a library that allows you to implement it. If you don't have a design, select a library that lets you create UI components quickly and customize them easily later. Here's a list of libraries I would consider:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://mui.com/" rel="noopener noreferrer"&gt;Material UI&lt;/a&gt; 📦&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://chakra-ui.com/" rel="noopener noreferrer"&gt;Chakra UI&lt;/a&gt; 🌈&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://ant.design/" rel="noopener noreferrer"&gt;Ant Design&lt;/a&gt; 🐜&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tailwindui.com/" rel="noopener noreferrer"&gt;Tailwind UI&lt;/a&gt; 🌟&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ant Design has almost everything you need, but it can be challenging to customize at times. Plus, it comes with tools for form handling and validation, so you don't have to think about that separately. That's why I often choose it. Of course, there's another option: creating your own component library. But I don't think any of your clients can afford that.&lt;/p&gt;

&lt;p&gt;It's also crucial to document your component library using &lt;a href="https://storybook.js.org/" rel="noopener noreferrer"&gt;Storybook&lt;/a&gt;. It doesn't take much time, but it will be incredibly helpful for you and your team in the future. 📚&lt;/p&gt;

&lt;h2&gt;
  
  
  Styling Approach 🎩
&lt;/h2&gt;

&lt;p&gt;Customizing your UI components depends a lot on the component library you choose. In the case of Material UI, you'll have to live with their CSS in JS approach, which I'm not entirely fond of. Because in some cases, you'll need to use components from other libraries, and then you'll have to mix different styling approaches. It looks terrible in a project! Therefore, I would choose a library that allows the use of CSS modules, such as Chakra UI or Ant Design. This way, you'll achieve a consistent styling approach throughout the project.&lt;/p&gt;

&lt;h3&gt;
  
  
  TailwindCSS?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28f3mklepdunt6jhtwox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28f3mklepdunt6jhtwox.png" alt="TailwindCSS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I personally like Tailwind, and if I had to create my component library, I would definitely choose it because it's convenient. But, as I mentioned earlier, having consistency in my project is essential to me, and I can't afford to write some things in CSS Modules and others directly in markup. So, I wouldn't choose it for my project. Still, I can say with confidence that it's a good tool, and if you're not afraid of experiments, you can try it in your project. 🛠️&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion 🎉
&lt;/h2&gt;

&lt;p&gt;Starting a React project involves key considerations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Requirements:&lt;/strong&gt; Gather comprehensive project details, from browser support to design assets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Common Components:&lt;/strong&gt; Include authentication, routing, state management, UI elements, internationalization, styling, and code quality tools.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Frameworks:&lt;/strong&gt; Choose wisely based on team expertise and project requirements. Experimentation is best suited for personal projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;State Management:&lt;/strong&gt; Divide state management into server-side and client-side. Tools like Apollo, RTK Query, SWR, and react-query can be invaluable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;UI Components:&lt;/strong&gt; Select libraries like Material UI, Chakra UI, Ant Design, or Tailwind UI based on design needs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Styling:&lt;/strong&gt; Prioritize consistent styling. Consider tools like Chakra UI or Ant Design with CSS modules for uniformity.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In summary, make informed choices aligned with project goals. Document decisions, and stay adaptable to evolving project needs. 🚀&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Infer keyword in TypeScript 📜</title>
      <dc:creator>0ro</dc:creator>
      <pubDate>Tue, 22 Aug 2023 22:13:56 +0000</pubDate>
      <link>https://dev.to/0ro/infer-keyword-in-typescript-3nig</link>
      <guid>https://dev.to/0ro/infer-keyword-in-typescript-3nig</guid>
      <description>&lt;p&gt;TypeScript's &lt;strong&gt;infer&lt;/strong&gt; keyword is your secret weapon for effortlessly deducing types, simplifying code, and unlocking the full potential of type inference. In this article, we'll explore how infer can make your TypeScript development smoother and more efficient. 🚀 &lt;/p&gt;

&lt;p&gt;Type inference in TypeScript is used to provide type information when there is no explicit type annotation. This usually occurs when you haven't added types to your variables:&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// str is a string here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything is fine with this; TypeScript handles it for you. 👍&lt;/p&gt;

&lt;p&gt;If you want to try type inference yourself you can use the &lt;strong&gt;infer&lt;/strong&gt; keyword, and it will look like this:&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// str is a string&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;GetType&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;infer&lt;/span&gt; &lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;never&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;T1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;GetType&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, this example may seem strange and not interesting, but it can give you an idea of how the &lt;strong&gt;infer&lt;/strong&gt; keyword can be used later. 🤔 &lt;/p&gt;

&lt;p&gt;As you can see, we used &lt;strong&gt;infer&lt;/strong&gt; within &lt;strong&gt;a conditional&lt;/strong&gt; statement, and this is a limitation of using &lt;strong&gt;infer&lt;/strong&gt; in TypeScript. Also, you &lt;strong&gt;cannot&lt;/strong&gt; use it outside of an &lt;strong&gt;extends&lt;/strong&gt; clause.&lt;/p&gt;

&lt;p&gt;If you want to extract the type of an element inside an array, you can do it like this:&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;GetTypeOfArrayElement&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;infer&lt;/span&gt; &lt;span class="nx"&gt;S&lt;/span&gt;&lt;span class="p"&gt;)[]&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;S&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;never&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;T1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;GetTypeOfArrayElement&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the &lt;strong&gt;infer&lt;/strong&gt; keyword allows you to extract the type within the array and then use it. It's like defining a reference that you can use later.&lt;/p&gt;

&lt;p&gt;That example, also might not seem very interesting because, in the end, you can achieve the same with this approach:&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="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;T2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, TypeScript has more complex structures that you cannot work around with simple syntax. Let's consider promises. What if you need to determine the type of the value returned by a promise? Here is where &lt;strong&gt;infer&lt;/strong&gt; can also help you:&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;promise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// Promise&amp;lt;number[]&amp;gt;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;GetTypeOfPromise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;infer&lt;/span&gt; &lt;span class="nx"&gt;S&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;S&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;never&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;T1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;GetTypeOfPromise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;promise&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// number[]&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;T2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;GetTypeOfPromise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// number&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;T3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;GetTypeOfPromise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// string[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By the way, Typescript itself already have a built-in utility for it that has more powerful functionality 👏:&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="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;T4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Awaited&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;promise&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;// number[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go further. The gaining access to function arguments can be defined like this:&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="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;GetTypeOfFirstArgument&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;infer&lt;/span&gt; &lt;span class="nx"&gt;U&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;U&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;never&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;T1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;GetTypeOfFirstArgument&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// string&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;T2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;GetTypeOfFirstArgument&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arg1&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="nx"&gt;arg2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in the end, maybe the most practical example with React component function.&lt;/p&gt;

&lt;p&gt;It can happen that in some libraries, they didn't export the props for their component. But in your code, you really need it. So with &lt;strong&gt;infer&lt;/strong&gt; keyword getting the prop type is possible, and will look like this:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;OutsideComponent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FC&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&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="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;InferProps&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FC&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;infer&lt;/span&gt; &lt;span class="nx"&gt;P&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;P&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;never&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;InferProps&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;OutsideComponent&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This technique allows you to infer the prop types of a React component function even if they aren't explicitly exported&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Incorporating &lt;strong&gt;infer&lt;/strong&gt; into your TypeScript toolkit can significantly streamline your code, simplify complex type manipulations, and boost your development productivity. Embrace this powerful keyword to unlock the true potential of type inference in TypeScript. Happy coding! 🚀&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>react</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🎯 300+ LeetCode Problems are solved: What I Discovered! 💡</title>
      <dc:creator>0ro</dc:creator>
      <pubDate>Thu, 17 Aug 2023 16:53:01 +0000</pubDate>
      <link>https://dev.to/0ro/300-leetcode-problems-are-solved-what-i-discovered-i46</link>
      <guid>https://dev.to/0ro/300-leetcode-problems-are-solved-what-i-discovered-i46</guid>
      <description>&lt;p&gt;A year ago, I began solving problems on LeetCode. 🚀 Since then, I have successfully finished 300+ problems, and here are my thoughts and conclusions about this journey. 💡&lt;/p&gt;

&lt;p&gt;I'm a technical leader in an outsourcing tech company. The last time I attempted a job interview was three years ago, with this company. Now, I've decided to update my interview skills, not necessarily to change my current job, but to explore something new. Frankly, I wasn't entirely new to algorithms, but I had never systematically learned them on a daily basis.&lt;/p&gt;

&lt;p&gt;My previous interviews were more like improvisations on unfamiliar problems within a one-hour timeframe. Due to this approach, my results lacked consistency, and most of the time I failed. If you find yourself in a similar situation, this article could be helpful, as I aim to provide a plan. 🎯&lt;/p&gt;

&lt;p&gt;So, as mentioned earlier, a year ago, I decided to change this situation, gain confidence, and improve as a specialist. I wasn't aiming for FAANG or any specific destination; I just wanted to handle interviews with minimal stress. I didn't set a concrete goal, so I wasn't afraid of failure. It might not be the typical motivational advice, but it worked for me. 💪&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advice 1: Keep it Simple and Light ✨&lt;/strong&gt;&lt;br&gt;
I can't claim a 100% success rate in coding interviews now, but luck isn't the only factor anymore.&lt;/p&gt;

&lt;p&gt;Everyone learns at their own pace; don't compare yourself to those who solve problems faster. There will always be someone better. I'm not the most productive person, and I was unsure where to start learning algorithms. After some research, I found lists of LeetCode patterns that others had compiled and collected. I used one of these lists, but there are many others available that you can find in the google.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advice 2: Choose a Problem List as Your Guide 📚&lt;/strong&gt;&lt;br&gt;
All problems have underlying similarities, and people have already categorized them into patterns. Learning these patterns enables you to recognize them during interviews. Therefore, focus on learning patterns rather than how to solve individual problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advice 3: Learn Patterns, Not Problem Memorization 🧩&lt;/strong&gt;&lt;br&gt;
Surprisingly, the "Easy" problems on LeetCode aren't always easy. In my experience, LeetCode problems can be classified as follows:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Easy level:&lt;/strong&gt; Problems with simple patterns and common use cases, or even problems lacking a clear pattern.&lt;br&gt;
&lt;strong&gt;Medium level:&lt;/strong&gt; Problems with patterns that require additional techniques or data structures for solving, or problems with non-trivial use cases for simple patterns.&lt;br&gt;
&lt;strong&gt;High level:&lt;/strong&gt; Problems that combine two or more patterns and data structures.&lt;/p&gt;

&lt;p&gt;As you can see, without understanding basic patterns, solving "Easy" problems efficiently on LeetCode becomes a challenge, especially when you need to solve them with optimal time and memory complexity. 🤔&lt;/p&gt;

&lt;p&gt;I used this &lt;a href="https://seanprashad.com/leetcode-patterns/"&gt;list of patterns&lt;/a&gt; for my preparation, but you can use another; it's just an example of what it usually looks like. 😊&lt;/p&gt;

&lt;p&gt;Here is my top list of patterns that I didn't know, and I would have never arrived at them during an interview. So, if you learn them, it increases your chances of passing the interview. I've ordered them by the number of problems you can solve by learning each pattern: 📈&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;BFS/DFS/backtracking&lt;/strong&gt; - these patterns are amazing; once you understand them, they will stay with you for the rest of your life. Many problems on LeetCode can be solved using these patterns, even problems from the dynamic programming section (not optimally, but still). If you have limited time, focus on learning these patterns – it's your best shot. 🌟&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Search algorithms&lt;/strong&gt;, including binary search, merge, bucket, divide and conquer, and quick sort. 🔍&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Heap/Priority Queue&lt;/strong&gt;. This is an interesting data structure that I had only heard about before and didn't know how it worked internally. Since it was entirely new to me, this pattern seemed very useful, especially if it's not available in your programming language. ⚙️&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trie&lt;/strong&gt;. Another data structure pattern that's very helpful to know; you definitely can't invent it during an interview. 🌳&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I followed this strategy when solving LeetCode problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Read the problem. 👀&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not&lt;/strong&gt; start coding. ❌&lt;/li&gt;
&lt;li&gt;Understand the problem. 🤔&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not&lt;/strong&gt; start coding! ❌&lt;/li&gt;
&lt;li&gt;Examine the constraints. 📋&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not&lt;/strong&gt; start coding!! ❌&lt;/li&gt;
&lt;li&gt;Find the pattern for solving it. 🧩&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not&lt;/strong&gt; start coding!!! ❌&lt;/li&gt;
&lt;li&gt;If you discover a pattern and solution, talk it out loud, and finally, &lt;strong&gt;write the code&lt;/strong&gt;. If not, explore related topics – it might spark an idea; if that doesn't help, proceed to submissions. 💡&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As you can observe, the most challenging part is refraining from immediately starting to code a solution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advice 4: Find the solution, then code it.&lt;/strong&gt; 💡👨‍💻&lt;/p&gt;

&lt;p&gt;There will be times when you feel slow and frustrated, but remember that some algorithms are built upon problems that were previously solved by scientists who might have even received Nobel prizes for their work. 🥇🧠&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I enjoyed the time I spent solving these problems. Of course, if you don't use it, you quickly forget it. However, I'm confident that if you tackle it once, the next time will be faster. Leave a comment how many problems you already solved on Leetcode, share your strategy, I will really appreciate it. Good Luck! 🚀🍀&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>programming</category>
      <category>algorithms</category>
      <category>career</category>
    </item>
    <item>
      <title>🚀 VSCode + Vim: The Perfect Match for Coding Domination 💪</title>
      <dc:creator>0ro</dc:creator>
      <pubDate>Tue, 15 Aug 2023 18:58:43 +0000</pubDate>
      <link>https://dev.to/0ro/vscode-vim-the-perfect-match-for-coding-domination-3kfo</link>
      <guid>https://dev.to/0ro/vscode-vim-the-perfect-match-for-coding-domination-3kfo</guid>
      <description>&lt;p&gt;There are already many stories about Vim, detailing how it is useful for developers' lives. It makes screen sharing easier during the interview process or when pair programming at your current job, as familiarity with Vim makes you faster at coding. This enables you to quickly test all your ideas and select the best one. This is my story of adopting Vim and how I grew to love it.&lt;/p&gt;

&lt;h2&gt;
  
  
    First attempts 👶
&lt;/h2&gt;

&lt;p&gt;When I began my journey as a programmer, I used to work in the Sublime Text editor—almost everyone at that time used it. And I was content. Only now do I realize how slow I was. However, back then, I wasn't very proficient in programming; I had just started. The pace of my thoughts matched the speed of my typing. So, everything was satisfactory for me—I had never been hindered by typing speed or my efficiency.&lt;/p&gt;

&lt;p&gt;  After several years of active programming, I switched to VSCode and began to realize that something was amiss with my efficiency—not due to VSCode itself, but due to how I worked and wrote my code. This was despite the fact that I had learned all the hotkeys that my teammates had never heard of. One day, I came across a video on YouTube showcasing a person performing editor magic. It seemed like he was a hacker character from those movies where they never touch a mouse and just type incredibly fast. It was at that moment I comprehended how slow my speed was and that I needed to make some changes. That experience provided me with motivation; I wanted to be like that guy.  &lt;/p&gt;

&lt;p&gt;So, I discovered that the best way to learn Vim is through vimtutor. I'm using macOS, and if you are too, you already have it on your computer. Simply run this command in your terminal:&lt;br&gt;
&lt;br&gt;
  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; vimtutor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NqbFUzRL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zv01kovx2kg13jf5mkbh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NqbFUzRL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zv01kovx2kg13jf5mkbh.png" alt="vimtutor" width="734" height="483"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; It's a nice starting point if you want to give Vim a try. By the way, in lesson 1.2, they will explain how to exit from Vim, so you will not be lost. Don't worry.&lt;/p&gt;

&lt;p&gt;  I gave it a try as well, attempting to integrate it into my actual coding workflow, but I found myself uncertain about the next steps. It seemed that everyone in the Vim world had their own Vim configuration with plugins and customized settings. For me, this complexity felt like a challenge—it wasn't user-friendly, and I couldn't even locate the starting point for this journey. So, I abandoned it and returned to VSCode. Nevertheless, thoughts of Vim lingered. I tried it time and again, but without success, ultimately leading me to give up.&lt;/p&gt;

&lt;p&gt;After several months of tormenting myself, feeling ineffective, I finally reached a compromise.&lt;/p&gt;

&lt;h2&gt;
  
  
   The compromise 🤝
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Hua9UA3H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9oivc7djd6a44c1kz57n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hua9UA3H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9oivc7djd6a44c1kz57n.png" alt="vim extension" width="500" height="92"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; The compromise came in the form of the Vim extension for VSCode. It seemed to offer the easiest way to integrate Vim into my real-life workflow; all I needed was familiarity with vimtutor. So, I installed it and began using it. Admittedly, my initial progress was slow—slower than my regular mouse movements and VSCode shortcuts. However, I was determined to improve. After two weeks of consistent effort, my speed surpassed what I had achieved without Vim. &lt;/p&gt;

&lt;p&gt;Some Vim enthusiasts, who are deeply attached to the Vim editor, often contend that Vim plugins are inferior versions of Vim itself. These plugins are often restricted to the code area of your editor, whereas the original Vim gives you full control over various aspects, such as navigating through your file tree using Vim commands, among other things.&lt;/p&gt;

&lt;p&gt;I discovered a way to bring this functionality to VSCode. If you're already familiar with VSCode's keybinding system, you know that you can map keys to specific VSCode actions. Now, armed with Vim knowledge, you can adapt this to your keybinding system. For instance, if you want to move between tabs in VSCode, you can press &lt;code&gt;alt+h&lt;/code&gt; or &lt;code&gt;alt+l&lt;/code&gt; since &lt;code&gt;h&lt;/code&gt; and &lt;code&gt;l&lt;/code&gt; correspond to left and right movements in Vim. Similarly, to focus on the explorer panel, &lt;code&gt;ctrl+h&lt;/code&gt; can be pressed as it's located on the left side of your text editor, and so on.&lt;/p&gt;

&lt;p&gt;To make adoption for you easier, I'm happy to share &lt;a href="https://gist.github.com/0ro/ea0e44bdc3cb1a94ef03d8426ef32195"&gt;my keybinding configuration&lt;/a&gt; with you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion 🎉
&lt;/h2&gt;

&lt;p&gt;To summarise, here's all you need to do, to bring VIM in your coding life now:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Complete vimtutor.&lt;/li&gt;
&lt;li&gt; Install the Vim extension in VSCode.&lt;/li&gt;
&lt;li&gt; Edit your keybindings.json file (navigate to keyboard shortcuts in Settings, then switch to the JSON version).&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>vim</category>
      <category>vscode</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>🚀 One Git Trick for Perfect Commits 🛠️</title>
      <dc:creator>0ro</dc:creator>
      <pubDate>Tue, 15 Aug 2023 15:04:04 +0000</pubDate>
      <link>https://dev.to/0ro/one-git-trick-for-perfect-commits-3728</link>
      <guid>https://dev.to/0ro/one-git-trick-for-perfect-commits-3728</guid>
      <description>&lt;p&gt;Are you tired of seeing vague and meaningless commit messages like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fix: close pull request discussion
fix: fix review discussion
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're nodding your head in agreement, it might be time to introduce the "git fixup" technique to your team's workflow, or even just adopt it for yourself.&lt;/p&gt;

&lt;p&gt;If the concept seems complicated and overwhelming, don't worry – you're about to be pleasantly surprised. Git fixup is actually quite simple, especially if you're already comfortable with making commits. Let's jump right in! 🏊‍♂️&lt;/p&gt;

&lt;p&gt;Imagine you've made several commits on your working branch and have submitted a merge or pull request. However, during the code review, issues were identified—whether by your peers or during your own self-review. Instead of creating separate commits to address these problems, you can simply use the git fixup command. Here's how:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Identify the hash of the commit where the problem was found.&lt;/li&gt;
&lt;li&gt;Run the command💡:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;--fixup&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;commit &lt;span class="nb"&gt;hash &lt;/span&gt;you want to fix&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will generate a new commit with the original commit's subject, prefixed with &lt;code&gt;fixup!&lt;/code&gt;. This additional commit might seem like a slight inconvenience, but even it is already far better than having vague commit messages cluttering your history.&lt;/p&gt;

&lt;p&gt;But we're not done yet. The next step is to incorporate the fixup commit into the original commit using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git rebase &lt;span class="nt"&gt;--autosquash&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what these parameters mean:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-i&lt;/code&gt;: Interactive mode for the rebase.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--autosquash&lt;/code&gt;: A special flag that squashes fixup commits into their respective originals.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;main&lt;/code&gt;: The branch from which your current branch originated.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;!!! This is a rebasing command, and you should be aware that this command will change your Git History. So, do it only if you know how it works.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After executing this command, a text editor (VIM by default) will appear. Don't worry—there's no need to make changes. Simply close it by typing &lt;code&gt;:q!&lt;/code&gt;.&lt;/p&gt;

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

&lt;p&gt;Congratulations! Your commit history is now clean and organized. You're ready to share your changes with your team. Just use either of these commands to push your changes, depending on your circumstances:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if you work on the branch alone: &lt;code&gt;git push --force&lt;/code&gt; 💪&lt;/li&gt;
&lt;li&gt;if you share the branch with someone: &lt;code&gt;git push --force-with-lease&lt;/code&gt; 🤝&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To summarize:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Copy the hash of the commit you want to fix.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git commit --fixup=&amp;lt;commit hash&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Execute &lt;code&gt;git rebase --autosquash -i main&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Check the open text editor and close it if everything looks good (&lt;code&gt;:q!&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;git push --force&lt;/code&gt; to publish your changes.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>git</category>
      <category>programming</category>
      <category>productivity</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
