<?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>Forem: Sean Yasnogorodski</title>
    <description>The latest articles on Forem by Sean Yasnogorodski (@seanyasno).</description>
    <link>https://forem.com/seanyasno</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%2F974589%2F50d192fe-6441-44e1-98d9-b2b2d5a92ed6.jpeg</url>
      <title>Forem: Sean Yasnogorodski</title>
      <link>https://forem.com/seanyasno</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/seanyasno"/>
    <language>en</language>
    <item>
      <title>Handling Icons in React: Best Practices</title>
      <dc:creator>Sean Yasnogorodski</dc:creator>
      <pubDate>Thu, 03 Oct 2024 17:44:35 +0000</pubDate>
      <link>https://forem.com/seanyasno/handling-icons-in-react-best-practices-22c5</link>
      <guid>https://forem.com/seanyasno/handling-icons-in-react-best-practices-22c5</guid>
      <description>&lt;p&gt;Throughout my experience developing websites with React, I frequently encountered challenges with icons (especially those not sourced from libraries). One key question was: &lt;strong&gt;How can I handle my icons more efficiently in code?&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Switched to SVGs
&lt;/h2&gt;

&lt;p&gt;Initially, I used PNG and JPEG files for icons, but quickly realized their limitations. Switching to SVG files offered several advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scalability: SVGs can scale without losing quality.&lt;/li&gt;
&lt;li&gt;Faster Loading: SVG files are lightweight, improving load times.&lt;/li&gt;
&lt;li&gt;CSS Styling: SVGs can be easily styled directly in CSS.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Creating Icon Components
&lt;/h3&gt;

&lt;p&gt;After adopting SVGs, I structured my icon components like this:&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;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ExampleIcon&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;=&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;svg&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* svg code here */&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;svg&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;While this worked, I wanted more flexibility in styling and leveraging React’s component power. To achieve that, I added props to my icon components:&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;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ExampleIcon&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;SVGProps&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;SVGSVGElement&lt;/span&gt;&lt;span class="o"&gt;&amp;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="nx"&gt;props&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;svg&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&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="cm"&gt;/* svg code here */&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;svg&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;This allows us to pass all standard &lt;code&gt;svg&lt;/code&gt; element props to our icons.&lt;/p&gt;

&lt;h2&gt;
  
  
  Organizing Icons in React
&lt;/h2&gt;

&lt;p&gt;To keep my icons organized, I created an &lt;code&gt;icons&lt;/code&gt; folder and added a new component whenever I needed a new icon. This method worked for a while, but I wondered—is there a more efficient approach?&lt;/p&gt;

&lt;h2&gt;
  
  
  Discovering @svgr/cli
&lt;/h2&gt;

&lt;p&gt;After researching best practices, I came across &lt;a href="https://www.npmjs.com/package/@svgr/cli" rel="noopener noreferrer"&gt;@svgr/cli&lt;/a&gt;, a game-changing tool for handling SVGs in React. This CLI tool automatically generates React components from SVG files, saving time and improving maintainability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Generating Icon Components Automatically
&lt;/h3&gt;

&lt;p&gt;Instead of manually creating icon components, I could now run a single command to generate them:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx @svgr/cli icons/svgs --out-dir icons/components --typescript&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command converts all SVG files in the &lt;code&gt;svgs&lt;/code&gt; folder into TypeScript React components, placing them in the &lt;code&gt;icons/components&lt;/code&gt; folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building a Flexible &lt;code&gt;Icon&lt;/code&gt; Component
&lt;/h2&gt;

&lt;p&gt;To streamline the use of icons, I built a reusable &lt;code&gt;Icon&lt;/code&gt; component. Here’s the folder structure I used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
  components/
    icons/
  svgs/
  types/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;components/icons/&lt;/code&gt;: Contains generated icon components.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;svgs/&lt;/code&gt;: Stores raw SVG files.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;types/&lt;/code&gt;: Holds TypeScript types, including icon-type.ts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 1: Define Icon Type
&lt;/h3&gt;

&lt;p&gt;In &lt;code&gt;src/types/icon-type.ts&lt;/code&gt;, I defined the type for our icon components:&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="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Icons&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../components/icons&lt;/span&gt;&lt;span class="dl"&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;type&lt;/span&gt; &lt;span class="nx"&gt;IconType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kr"&gt;keyof&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;Icons&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This type ensures that &lt;code&gt;IconType&lt;/code&gt; corresponds to the names of the generated components, such as &lt;code&gt;Logo&lt;/code&gt; for a &lt;code&gt;Logo.tsx&lt;/code&gt; component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Create the &lt;code&gt;Icon&lt;/code&gt; Component
&lt;/h3&gt;

&lt;p&gt;Next, I created the &lt;code&gt;Icon.tsx&lt;/code&gt; file in &lt;code&gt;src/components/&lt;/code&gt;:&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;React&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;SVGProps&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&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="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;IconType&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../types/icon-type&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="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Icons&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./icons&lt;/span&gt;&lt;span class="dl"&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;type&lt;/span&gt; &lt;span class="nx"&gt;IconProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;SVGProps&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;SVGSVGElement&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;IconType&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;Icon&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;IconProps&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="nx"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Icons&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="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;span&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"custom-icon"&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;Component&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;span&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;This component dynamically renders the appropriate icon based on the &lt;code&gt;icon&lt;/code&gt; prop. For instance, to display the &lt;code&gt;Logo&lt;/code&gt; icon, you would use:&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;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;TestComponent&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;=&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;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Icon&lt;/span&gt; &lt;span class="na"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Logo"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&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;h3&gt;
  
  
  Step 3: Styling the Icons
&lt;/h3&gt;

&lt;p&gt;To ensure icons inherit the current text color, add the following to your global CSS file:&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;.custom-icon&lt;/span&gt; &lt;span class="nt"&gt;path&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.custom-icon&lt;/span&gt; &lt;span class="nt"&gt;rect&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;stroke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;currentColor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Automating Icon Generation
&lt;/h2&gt;

&lt;p&gt;To simplify the process, I added the following script to my &lt;code&gt;package.json&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"icons:generate": "npx @svgr/cli src/svgs --out-dir src/components/icons --typescript"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Final Flow
&lt;/h3&gt;

&lt;p&gt;Whenever you need to add a new icon to your project, simply:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Place the SVG file in the &lt;code&gt;svgs&lt;/code&gt; folder.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;npm run icons:generate&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use the new icon by referencing it in the &lt;code&gt;&amp;lt;Icon/&amp;gt;&lt;/code&gt; component with autocomplete support for icon names.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;I hope this article helps you handle icons more effectively in your React projects. Feel free to ask any questions — I'd love to help! 😊&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>tutorial</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Starting a new blogging journey with Docusaurus</title>
      <dc:creator>Sean Yasnogorodski</dc:creator>
      <pubDate>Tue, 29 Nov 2022 17:38:43 +0000</pubDate>
      <link>https://forem.com/seanyasno/starting-a-new-blogging-journey-with-docusaurus-3aap</link>
      <guid>https://forem.com/seanyasno/starting-a-new-blogging-journey-with-docusaurus-3aap</guid>
      <description>&lt;p&gt;For a really looooong time I wanted to start blogging. I had something in my heart that just kept pounding and I just didn't do anything with it. &lt;/p&gt;

&lt;p&gt;About more than a year ago I watched a video of &lt;a href="https://www.youtube.com/@aliabdaal" rel="noopener noreferrer"&gt;Ali Abdaal&lt;/a&gt; - &lt;a href="https://www.youtube.com/watch?v=vyVpRiqOvt4" rel="noopener noreferrer"&gt;How Writing Online Made me a Millionaire&lt;/a&gt; and he recommended a book that's called &lt;a href="https://www.bookdepository.com/Show-Your-Work-Austin-Kleon/9780761178972?ref=grid-view&amp;amp;qid=1669199888199&amp;amp;sr=1-1" rel="noopener noreferrer"&gt;Show Your Work!&lt;/a&gt; by &lt;a href="https://austinkleon.com/" rel="noopener noreferrer"&gt;Austin Kleon&lt;/a&gt; and I immediately ordered it. Once I read it, all I wanted to do is to start blogging and sharing my knowledge and creating a small community. But as I said earlier, I just didn't do anything with it.&lt;/p&gt;

&lt;p&gt;And &lt;strong&gt;now&lt;/strong&gt; it's the time! Actually, 3 weeks ago I started blogging and I uploaded my &lt;a href="https://dev.to/seanyasno/how-to-structure-react-project-files-31dg"&gt;first blog&lt;/a&gt; (I also post these blogs on medium) and I just fell in love with writing blogs. So now every Tuesday I'm going to upload a new blog.&lt;/p&gt;

&lt;p&gt;I got a new plan and my plan is to create a new website under my own custom domain and upload all my blogs and my portfolio to that website. And to build that website I chose &lt;a href="https://docusaurus.io/" rel="noopener noreferrer"&gt;Docusaurus&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  🦖 What is actually Docusaurus?
&lt;/h2&gt;

&lt;p&gt;Basically it's a template website project created by Facebook in React that supports markdown files to upload documents, blogs and more. It also supports localization so you can translate your website to multiple languages, has document versioning and content search throughout the website. Also it supports &lt;strong&gt;dark mode&lt;/strong&gt; out the box!&lt;/p&gt;

&lt;p&gt;If you look sometimes in some NPM packages docs website, it might came to your head that a lot of these website looks very similar, and one of the reason is that they might be using Docusaurus!&lt;/p&gt;

&lt;h2&gt;
  
  
  ✍🏻 Why I chose Docusaurus to write blogs?
&lt;/h2&gt;

&lt;p&gt;I've been a Full-Stack developer for the last couple years and one thing that I learnt as a Full-Stack developer is that to become a Senior you need to become a lazy developer. Let me explain.&lt;/p&gt;

&lt;p&gt;Lazy developer is developer that uses the right tools to create something great in a short time without the need to write it by yourself from scratch. At the end you're being paid by your project quality and by time delivery, and if you can't deliver both, then you need to get better. &lt;/p&gt;

&lt;p&gt;So since I'm a lazy developer, I tried to find a tool that would help me to create a blogging website but still I would have the ability to customize and code the website. And Docusaurus answers it all!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It has super responsive UI with mobile support&lt;/li&gt;
&lt;li&gt;It supports localization&lt;/li&gt;
&lt;li&gt;I can add blogs and portfolio and other pages&lt;/li&gt;
&lt;li&gt;I can create my own custom pages and components&lt;/li&gt;
&lt;li&gt;I can code it with React and TypeScript&lt;/li&gt;
&lt;li&gt;It supports dark mode&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🏁 Let's get started!
&lt;/h2&gt;

&lt;p&gt;So how do you exactly start a new Docusaurus project? The answer is - with one line of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-docusaurus@latest my-website classic &lt;span class="nt"&gt;--typescript&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since I'm using &lt;strong&gt;TypeScript&lt;/strong&gt; (and you should too) I added the &lt;code&gt;--typescript&lt;/code&gt; flag but if from some reason you prefer to write in &lt;strong&gt;JavaScript&lt;/strong&gt;, then you can omit &lt;code&gt;--typescript&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After that you can start your new website by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will start your website and you can see it by going to the url &lt;code&gt;localhost:3000&lt;/code&gt;. Then you will see your new homepage:&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%2Fp5coasehozyvfjwjxclo.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%2Fp5coasehozyvfjwjxclo.png" alt="New Docusaurus Home Page Template" width="800" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🎯 My Current Plan
&lt;/h2&gt;

&lt;p&gt;As I said in the beginning, I want to create a blogging website and also I want to upload my portfolio to that website too. So for now I made a little list to what I should do next:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Change website theme&lt;/li&gt;
&lt;li&gt;Modify project configuration&lt;/li&gt;
&lt;li&gt;Work on custom Design and Layout&lt;/li&gt;
&lt;li&gt;Add a search bar&lt;/li&gt;
&lt;li&gt;Upload my first blog post&lt;/li&gt;
&lt;li&gt;Deploy site in Vercel&lt;/li&gt;
&lt;li&gt;Create an about page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As the project grows, new todos will be added to that list and I can't wait to see how it is going to be! &lt;/p&gt;

&lt;p&gt;I will continue updating you about this project and since it's going to be an open source project I'll share the link with you as soon as it goes live!&lt;/p&gt;




&lt;p&gt;I hope you find this article useful and that you learn something new that you didn't know before. I'm more than happy to reply to any questions that you have on your mind :)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>opensource</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to add absolute paths to your TypeScript Project</title>
      <dc:creator>Sean Yasnogorodski</dc:creator>
      <pubDate>Tue, 22 Nov 2022 21:57:45 +0000</pubDate>
      <link>https://forem.com/seanyasno/how-to-add-absolute-paths-to-your-typescript-project-b62</link>
      <guid>https://forem.com/seanyasno/how-to-add-absolute-paths-to-your-typescript-project-b62</guid>
      <description>&lt;p&gt;In every project we've got to import something. It can be a file from somewhere else from the project or it can be a node module. Today I'm going to teach you how to become a pro at importing files and import a file the right way.&lt;/p&gt;

&lt;h2&gt;
  
  
  What do we need?
&lt;/h2&gt;

&lt;p&gt;First, we need a TypeScript project. If you use a JavaScript project, then you need to add TypeScript to it. I'm going to create a new &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt; project with &lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; using &lt;a href="https://vitejs.dev/" rel="noopener noreferrer"&gt;Vite&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-vite-app example &lt;span class="nt"&gt;--template&lt;/span&gt; react-ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since Vite doesn't install node dependencies automatically, we need to install it ourself.&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="nb"&gt;cd &lt;/span&gt;example
npm i
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After it will install all node dependencies in our project, we can open the project and start coding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding an example
&lt;/h2&gt;

&lt;p&gt;If you know what you're doing, you can skip this section and move on to the next section. If you're a beginner, you should continue reading and follow the example.&lt;/p&gt;

&lt;p&gt;Let's create a &lt;code&gt;utils&lt;/code&gt; folder inside &lt;code&gt;src&lt;/code&gt; directory. Inside &lt;code&gt;utils&lt;/code&gt; folder create a new file and call it &lt;code&gt;index.ts&lt;/code&gt;. It should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg6gmholyqw01m8qwlh65.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg6gmholyqw01m8qwlh65.png" alt="A Vite react typescript project folder content screenshot" width="234" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's create a function inside &lt;code&gt;index.ts&lt;/code&gt; file:&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;first&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="nx"&gt;second&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="kr"&gt;number&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="nx"&gt;first&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;second&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;Now create a &lt;code&gt;components&lt;/code&gt; folders and move &lt;code&gt;App.tsx&lt;/code&gt; inside. After that open &lt;code&gt;App.tsx&lt;/code&gt; file and try importing &lt;code&gt;addition&lt;/code&gt; function from &lt;code&gt;utils&lt;/code&gt;. You'll get 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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;addition&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../utils&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;Our goal is to avoid all these &lt;code&gt;../&lt;/code&gt; dots so we would have a very simple import that we can just copy and paste it without changing something throughout the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating our first absolute path
&lt;/h2&gt;

&lt;p&gt;Open &lt;code&gt;tsconfig.json&lt;/code&gt; file and go into &lt;code&gt;"compilerOptions"&lt;/code&gt; section. At the end of the section add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"paths"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"@utils/*"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"src/utils/*"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that is it! You created your first absolute path! You can back to &lt;code&gt;App.tsx&lt;/code&gt; and change the import from:&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;addition&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../utils&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;to:&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;addition&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@utils/index&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;But let's go back for a second. Let's take a part the line that we added inside &lt;code&gt;"paths"&lt;/code&gt; section in &lt;code&gt;tsconfig.json&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"@utils/*"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"src/utils/*"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The name &lt;code&gt;@utils&lt;/code&gt; is actually the prefix that we want to call before something we want to import from the &lt;code&gt;utils&lt;/code&gt; folder. We can call it however we want. if we change &lt;code&gt;@utils/*&lt;/code&gt; to &lt;code&gt;@shrek/*&lt;/code&gt;, than every time we import something from the utils folder, 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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;addition&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@shrek/index&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;Inside the array we have &lt;code&gt;src/utils/*&lt;/code&gt;. We actually specify in this array all the files we'd like to import using the prefix we have defined. &lt;/p&gt;

&lt;p&gt;And that's basically it! That's how you can add absolute paths into your project and make your imports much more shorter and much more satisfying!&lt;/p&gt;




&lt;p&gt;I hope you find this article useful and that you learn something new that you didn't know before. I'm more than happy to reply to any questions that you have on your mind :)&lt;/p&gt;

</description>
      <category>solidity</category>
    </item>
    <item>
      <title>How to add ESLint, Prettier, and Husky to your Web / NodeJS project</title>
      <dc:creator>Sean Yasnogorodski</dc:creator>
      <pubDate>Sun, 20 Nov 2022 12:52:07 +0000</pubDate>
      <link>https://forem.com/seanyasno/how-to-add-eslint-prettier-and-husky-to-your-web-nodejs-project-4h5j</link>
      <guid>https://forem.com/seanyasno/how-to-add-eslint-prettier-and-husky-to-your-web-nodejs-project-4h5j</guid>
      <description>&lt;p&gt;Every web developer that writes in NodeJS/React/NextJS/Angular/Vite should use &lt;a href="https://eslint.org/"&gt;ESLint&lt;/a&gt;, &lt;a href="https://prettier.io/"&gt;Prettier&lt;/a&gt;, and &lt;a href="https://typicode.github.io/husky/#/"&gt;Husky&lt;/a&gt;. You must be familiar already with ESLint and maybe you have heard about the other two before but if not, I'm going to do some order in your head about each one and how you can use it and implement it in your own project. So let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding ESLint
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--14tgjHCN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bcoxh39d2yxuzadark6i.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--14tgjHCN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bcoxh39d2yxuzadark6i.jpeg" alt="A logo of eslint" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://eslint.org/"&gt;ESLint&lt;/a&gt; is a straightforward linting tool that helps identify problematic patterns in your code before you build your code and also on the way while you're coding.&lt;/p&gt;

&lt;p&gt;As a developer, one of my goals is to write better code with minimal errors to save time on debugging and failed builds. One way to get better with code syntax and get better coding is using &lt;strong&gt;ESLint&lt;/strong&gt;. You can find problems quickly, fix problems automatically and you can configure it for yourself for how you like the code to be.&lt;/p&gt;

&lt;p&gt;One quick way to add &lt;strong&gt;ESLint&lt;/strong&gt; to your project is simply running the following line in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx eslint &lt;span class="nt"&gt;--init&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running this command you'd be asked a couple of questions and when it's done it'll install for you all the packages you need automatically and generate a &lt;code&gt;.eslintrc.json&lt;/code&gt; file in your root folder.&lt;/p&gt;

&lt;p&gt;You can add plugins to your &lt;strong&gt;ESLint&lt;/strong&gt; config file and you can change the rules to how you like to write your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Prettier
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kocwS-kZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c28fvmhzecxhz9abegvc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kocwS-kZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c28fvmhzecxhz9abegvc.jpg" alt="A prettier logo" width="640" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://prettier.io/"&gt;Prettier&lt;/a&gt; is a code formatter. When you add &lt;strong&gt;Prettier&lt;/strong&gt; to your code you can integrate it with your editor and while you're saving the code will automatically format itself to your preferences.&lt;/p&gt;

&lt;p&gt;It saves time in teams because it enforces the same code style and does it automatically so you don't have to argue each time in a code review that you forgot a semicolon at the end of a line.&lt;/p&gt;

&lt;p&gt;In order to add Prettier to your project you need to install it via &lt;code&gt;npm&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; &lt;span class="nt"&gt;--save-exact&lt;/span&gt; prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you add it to your project you can go into your editor's settings and change it to run &lt;strong&gt;Prettier&lt;/strong&gt; so it can format your code each time you're saving a file. Also, you can add it to format your project each time you run a build or something like that.&lt;/p&gt;

&lt;p&gt;You can use this line to format your code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx prettier &lt;span class="nt"&gt;--write&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Adding Husky
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hy0wwL6m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/it0cwc1r7ctkkqyfkn9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hy0wwL6m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/it0cwc1r7ctkkqyfkn9k.png" alt="A Husky logo" width="225" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I guess if you come so far and you know more than coding, then you know about git. &lt;a href="https://typicode.github.io/husky/#/"&gt;Husky&lt;/a&gt; is a tool that makes it easier to write git hooks and helps with your code flow.&lt;/p&gt;

&lt;p&gt;For example, you can create a commit git hook that each time you do the command git commit then it will run tests, lint your code, lint your commit messages, and more! So let's see how we do that:&lt;/p&gt;

&lt;p&gt;First, let's add &lt;strong&gt;Husky&lt;/strong&gt; to our project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;husky &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second, enable git hooks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx husky &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can create your first hook! Let's create a pre-commit hook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx husky add .husky/pre-commit &lt;span class="s2"&gt;"npm test"&lt;/span&gt;
git add .husky/pre-commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you run these commands you'll see a folder with the name &lt;code&gt;.husky&lt;/code&gt; being created at the root of your project folder and it's the same &lt;code&gt;pre-commit&lt;/code&gt; hook that we have created. You can now run &lt;code&gt;git commit&lt;/code&gt; to see how it's working 😄&lt;/p&gt;




&lt;p&gt;I really recommend to you use these three tools and you'll see how much your workflow will be improved and also see how you will write better code.&lt;/p&gt;

&lt;p&gt;I hope you find this article useful and that you learn something new that you didn't know before. I'm more than happy to reply to any questions that you have on your mind :)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>react</category>
    </item>
    <item>
      <title>How To Structure React Project Files</title>
      <dc:creator>Sean Yasnogorodski</dc:creator>
      <pubDate>Sun, 20 Nov 2022 11:38:45 +0000</pubDate>
      <link>https://forem.com/seanyasno/how-to-structure-react-project-files-31dg</link>
      <guid>https://forem.com/seanyasno/how-to-structure-react-project-files-31dg</guid>
      <description>&lt;p&gt;There are a lot of different ways and approaches for creating a concrete project file structure for different coding frameworks. Today I’m going to bring you an approach that I’ve been using and structuring through my years in the industry that I think has more advantages than other project file structures you’ll see online.&lt;/p&gt;

&lt;h3&gt;
  
  
  Choosing a Framework
&lt;/h3&gt;

&lt;p&gt;Before we start with anything, we first need to choose which framework library we’re going to use to write our project. You can select the default React framework library but you can also select a faster framework library that has been built on React. Here are two examples you can choose from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/"&gt;Next.JS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vitejs.dev/"&gt;Vite&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both are lightweight, powerful, and useful and I suggest choosing one of these two options over the default &lt;code&gt;create-react-app&lt;/code&gt; option. For this example, I’m going to use &lt;strong&gt;Next.JS&lt;/strong&gt; with &lt;strong&gt;TypeScript&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Our Project
&lt;/h3&gt;

&lt;p&gt;As I said earlier, I’m going to use Next.JS with TypeScript, and in case you don’t know or forgot how to create one, here’s the line of code using &lt;code&gt;NPM&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-next-app@latest &lt;span class="nt"&gt;--ts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After choosing a name and waiting for a minute, we get a blank &lt;strong&gt;Next.JS TypeScript&lt;/strong&gt; project template.&lt;/p&gt;

&lt;h3&gt;
  
  
  Our New Folder Structure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src
    abstraction
        enums
        models
        types
    assets
        icons
        images
    components
    constants
    hooks
    mocks
    requests
    styles
    theme
    utils
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So this is our new folder structure. As you can see we created around 13–15 different folders that we’re going to use with each one. Now let’s dive into an explanation for each folder.&lt;/p&gt;

&lt;p&gt;Of course, outside of &lt;code&gt;src&lt;/code&gt; folder there should be other folders such as &lt;code&gt;node_modules&lt;/code&gt; and &lt;code&gt;public&lt;/code&gt;, and there should be other files such as &lt;code&gt;package.json&lt;/code&gt;, &lt;code&gt;.gitignore&lt;/code&gt; and &lt;code&gt;tsconfig.json&lt;/code&gt;. I won’t talk about these kinds of files and folders in this article.&lt;/p&gt;

&lt;h3&gt;
  
  
  Abstraction
&lt;/h3&gt;

&lt;p&gt;This is a very unique folder and you won’t see it much in any online tutorial, blogs, videos, etc. It’s a personal preference that I found very useful and helps with navigating through the project much easier.&lt;/p&gt;

&lt;p&gt;It contains three different folders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;enums&lt;/li&gt;
&lt;li&gt;models&lt;/li&gt;
&lt;li&gt;types&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The reason we grouped these three folders into one is that we’ve got a lot of similarities between the three and the only difference is the declaration type.&lt;/p&gt;

&lt;p&gt;For people that use interfaces instead/with types, you can add in &lt;code&gt;abstraction&lt;/code&gt; folder an `interfaces folder too.&lt;/p&gt;

&lt;h3&gt;
  
  
  Assets
&lt;/h3&gt;

&lt;p&gt;This folder can be placed in different places throughout the project and it depends on which framework you use. For now, I put it inside the &lt;code&gt;src&lt;/code&gt; folder as the other folders.&lt;/p&gt;

&lt;p&gt;Within these folders, all files that are not scripts and are being used in code should be placed. Examples of these kinds of assets:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Icons (Preferred to be SVG)&lt;/li&gt;
&lt;li&gt;Images&lt;/li&gt;
&lt;li&gt;Fonts&lt;/li&gt;
&lt;li&gt;Gifs&lt;/li&gt;
&lt;li&gt;Videos (Try to not save videos in project files and store them in the cloud and fetch them on start)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Components
&lt;/h3&gt;

&lt;p&gt;Probably this folder would be the biggest folder in your project over time since you’re going to create more and more components that you’ll use in your project.&lt;/p&gt;

&lt;p&gt;It’s important to keep here the components that are being reused through the project or that you think you might use somewhere in the future.&lt;/p&gt;

&lt;p&gt;Also, there is a folder structure for a &lt;code&gt;component&lt;/code&gt; folder. What I found useful is doing this:&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;component-name
    component-name.test.tsx
    component-name.tsx
    styles.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason the name of the component file and the test file is the same name as the folder is that it’ll be much easier to search for files in your project. If it was just an index file then you’ll have to type &lt;code&gt;component-name/index&lt;/code&gt; in order to get that file while you can just type &lt;code&gt;component&lt;/code&gt; and you’ll get a reference for the &lt;code&gt;component-name.tsx&lt;/code&gt; file much quicker.&lt;/p&gt;

&lt;p&gt;If in your component there are other components that are only being used in that component and won’t be used in other components, you can create a components folder inside your component and put those files there.&lt;/p&gt;

&lt;p&gt;In case you’re special and you do create test files and actually test your components, you should name the file as your component’s name with a following &lt;code&gt;test&lt;/code&gt; or &lt;code&gt;spec&lt;/code&gt; word (i.e. &lt;code&gt;component-name.test.tsx&lt;/code&gt;). It’ll be much easier to find your file this way.&lt;/p&gt;

&lt;p&gt;You can name your styles file however you like but since most of the time you rarely search for a specific component’s style file, I prefer to just name it as &lt;code&gt;styles.tsx&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Constants
&lt;/h3&gt;

&lt;p&gt;Sometimes you have a const value that won’t be changed and is used in different places inside your project or just a large const value that you’d like to save in a separate folder instead of where you’re using it. All these kinds of variables should be inside a constants folder.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hooks
&lt;/h3&gt;

&lt;p&gt;I really encourage you to create your own custom hooks. A lot of people don’t realize the potential you can get by creating custom hooks. Basically, if you have a couple of components with the same logic, you can just extract that logic into custom hooks and use that hook within those components.&lt;/p&gt;

&lt;p&gt;In addition, if you create a custom hook, don’t forget to test it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mocks
&lt;/h3&gt;

&lt;p&gt;Sometimes you use mock data instead of real data because you use it in testing, saving requests in development mode or even instead of a route that hasn’t built yet but you know how the data should come. Here you put all your mock files and forget about it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Requests
&lt;/h3&gt;

&lt;p&gt;Almost in any project, you’ll have to make requests to fetch, create, delete and mutate data. Here you should put all requests you’re going to make to external APIs. In each request file, you should write a simple function that fetches an API request with validation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Styles
&lt;/h3&gt;

&lt;p&gt;Each component has its own style file but when your project gets bigger and bigger, some components will have common styles. Those kinds of common styles should be extracted from those components and be in a separate file inside src/styles folder.&lt;/p&gt;

&lt;h3&gt;
  
  
  Theme
&lt;/h3&gt;

&lt;p&gt;Usually, when you use a components design framework library, there is a theme that you can create/edit. This kind of file should be here to get much easier access each time you’d like to edit something in your theme.&lt;/p&gt;

&lt;h3&gt;
  
  
  Utils
&lt;/h3&gt;

&lt;p&gt;Last and not least — the &lt;code&gt;utils&lt;/code&gt; folder. A simple folder that contains repetitive util functions that you use throughout your project. For example, a utils function that converts an image to &lt;code&gt;base64&lt;/code&gt; format should be in &lt;code&gt;utils&lt;/code&gt; folder.&lt;/p&gt;




&lt;p&gt;So this is my way of organizing my folder structure in my React projects that I find very useful for navigating and saving in the right order.&lt;/p&gt;

&lt;p&gt;There is also a lot more stuff that we didn’t talk about such as absolute imports, ESLint, Prettier, Husky, testing, and more. I encourage you to read about these topics too and step up your skills and make your project look and feel so much better.&lt;/p&gt;

&lt;p&gt;I hope you find this article useful and that you learn something new that you didn’t know before I’m more than happy to reply to any questions that you have on your mind :)&lt;/p&gt;

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