<?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: Don Hamilton III</title>
    <description>The latest articles on DEV Community by Don Hamilton III (@donhamiltoniii).</description>
    <link>https://dev.to/donhamiltoniii</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%2F266535%2Fcb9af13e-6451-4348-a9b7-5d6ab112a873.jpg</url>
      <title>DEV Community: Don Hamilton III</title>
      <link>https://dev.to/donhamiltoniii</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/donhamiltoniii"/>
    <language>en</language>
    <item>
      <title>VS Code Balance Out</title>
      <dc:creator>Don Hamilton III</dc:creator>
      <pubDate>Mon, 08 Jul 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/donhamiltoniii/vs-code-balance-out-2n5d</link>
      <guid>https://dev.to/donhamiltoniii/vs-code-balance-out-2n5d</guid>
      <description>&lt;p&gt;This article is more of a reminder than anything. &lt;a href="https://www.youtube.com/shorts/NwqhFb4B5LU" rel="noopener noreferrer"&gt;This video&lt;/a&gt; explains everything about this command and how to implement it. Essentially this is a way to select an entire HTML element with a key binding instead of having to hunt through the document on your own for an opening and closing tag. Super useful.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Using Git and Github Effectively</title>
      <dc:creator>Don Hamilton III</dc:creator>
      <pubDate>Wed, 07 Jun 2023 17:36:29 +0000</pubDate>
      <link>https://dev.to/donhamiltoniii/using-git-and-github-effectively-4imo</link>
      <guid>https://dev.to/donhamiltoniii/using-git-and-github-effectively-4imo</guid>
      <description>&lt;h1&gt;
  
  
  Using Git and Github Effectively
&lt;/h1&gt;

&lt;p&gt;Git and Github are very powerful tools for managing collections of files. Most people are familiar with using Git for programming version control and Github for maintaining remote versions of these programs. Git can be used for more than version control for programming, but it can also be a tool to maintain any project or directory of files that it would be helpful to have snapshots of over time.&lt;/p&gt;

&lt;p&gt;Following are some tips and practices that have helped me use git to not only more efficiently manage projects, but to also work with teams of developers on a code base. All of these tips should be able to be applied as best practices to any project that you are using git and Github to maintain. This will not be a comprehensive guide to using git. This article will provide useful tips that I have found useful to me in my projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  General Tips
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;HEAD&lt;/code&gt; just refers to the most recent commit on whatever branch you're on.
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;HEAD&lt;/code&gt; was a concept that took me a really long time to understand. &lt;code&gt;HEAD&lt;/code&gt; simply refers to your most recent commit on whatever branch you are currently on. Grasping that makes things like "detached &lt;code&gt;HEAD&lt;/code&gt; states" &lt;strong&gt;much&lt;/strong&gt; less confusing&lt;/p&gt;

&lt;h3&gt;
  
  
  Always use &lt;code&gt;git add -p&lt;/code&gt; instead of &lt;code&gt;git add .&lt;/code&gt; to avoid committing unintended files.
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;git add -p&lt;/code&gt; command goes through the changes that you haven't staged and asks you about changes &lt;strong&gt;one by one&lt;/strong&gt; and asks you &lt;strong&gt;if you want to include them on the current commit&lt;/strong&gt;. This might seem tedious, but it can save you a lot of time by avoiding commits that contain changes that should be saved for later, smaller commits.&lt;/p&gt;

&lt;h3&gt;
  
  
  Generally use &lt;code&gt;git commit -v&lt;/code&gt; instead of &lt;code&gt;git commit -m &amp;lt;message&amp;gt;&lt;/code&gt; to type a long form commit.
&lt;/h3&gt;

&lt;p&gt;Admittedly, one of the first reasons I started doing this was to get more familiar with Vim and editing files (especially small changes) from the command line. While using Vim is certainly a noble pursuit in and of itself, it is definitely a much better practice to have some sort of commit template in place when you are working with teams and sticking to it as much as possible. Examples of commit templates &lt;a href="https://blog.bitsrc.io/commit-message-best-practice-or-how-not-to-ruin-your-team-project-fc28d35fae31" rel="noopener noreferrer"&gt;can be found here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Always do a &lt;code&gt;git rebase -i&lt;/code&gt; before submitting a feature branch for PR.
&lt;/h3&gt;

&lt;p&gt;More on this in a later section, but this allows you to clean up your commits before showing people your work. Which means you can get rid of things like work-in-progress commits, merge commits that may be related to one another, rename commits after having more context for what they actually do, etc. It helps clean up your changes and gives your team, and future members of your team, a better idea of what work was done.&lt;/p&gt;




&lt;h2&gt;
  
  
  Stashing
&lt;/h2&gt;

&lt;p&gt;Stashing is a &lt;strong&gt;phenomenal&lt;/strong&gt; resource in git that I feel gets underused. Here is an example scenario. You are working on a branch in which you have progress you aren't ready to commit. A co-worker reaches out and asks you to review some work on another branch before they make a PR. You don't want to muddy up your commit history with a work-in-progress commit, but you don't want to move this work to your co-workers branch either. What do you do? Use &lt;code&gt;git stash&lt;/code&gt; instead! This saves a version of your current work in the stash list. Then when you finish and return to your original branch, simply reapply your previous changes using &lt;code&gt;git stash pop&lt;/code&gt;. Now you're back where you left off with no unneeded commits!&lt;/p&gt;




&lt;h2&gt;
  
  
  Time Travel and Undoing
&lt;/h2&gt;

&lt;p&gt;It's really useful to be familiar with restoring, resetting, and reverting. Now if you stick to good git practices, you can &lt;em&gt;usually&lt;/em&gt; avoid these. &lt;strong&gt;USUALLY&lt;/strong&gt;. But there are times when you or your teammates might add some code into a commit that shouldn't be there and you will need to do a little time traveling to work things out. The best thing about git is that it is truly almost impossible to blow work away forever. There is almost always a way to go back to previous states or recover code that might accidentally get deleted. So if you think you've irrecoverably broken something or lost all the work you did on that new feature, &lt;strong&gt;CALM DOWN&lt;/strong&gt;. You can fix it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;note:&lt;/em&gt; &lt;code&gt;HEAD~#&lt;/code&gt; refers to a way to specify a number of commits behind the current &lt;code&gt;HEAD&lt;/code&gt;. For example, if you simply want to go back one commit from where you are now in the commit tree, simply type &lt;code&gt;HEAD~1&lt;/code&gt; and go back one commit relative to where you are.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;git restore --source [&amp;lt;commit hash or HEAD~#&amp;gt;] &amp;lt;file-name&amp;gt;&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Unstage a file that is currently staged for commit or return a file to a state at a previous commit. Restore is usually used before you make a commit and you stage something you didn't mean to. (read: use &lt;code&gt;git add -p&lt;/code&gt; and not &lt;code&gt;git add .&lt;/code&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;git reset &amp;lt;commit-hash or HEAD~#&amp;gt;&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Reset is what you want to use when you need to undo an existing commit. Using the command above takes &lt;code&gt;HEAD&lt;/code&gt; back to specific commit but &lt;strong&gt;DOES NOT&lt;/strong&gt; remove changes. It brings files back to a new &lt;code&gt;HEAD&lt;/code&gt; for you to do as you please. So your files will almost look like you have a merge conflict and allows you to fix up your files as you need.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;git reset --hard &amp;lt;commit-hash or HEAD~#&amp;gt;&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Removes all commits following the specific commit and &lt;strong&gt;DOES&lt;/strong&gt; remove changes. All work from removed commits is lost. So essentially, this takes you back in time to whatever commit you specify and removes all of the commits you made after that point. &lt;strong&gt;BE CAREFUL&lt;/strong&gt; especially if you are going to be removing commits that have been pushed and may already be merged. This will not be fun to deal with in teams.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;git revert &amp;lt;commit-hash or HEAD~#&amp;gt;&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Removes changes to a given commit very much like &lt;code&gt;git reset&lt;/code&gt; &lt;strong&gt;BUT&lt;/strong&gt; creates a new commit with those changes instead of removing commits and changing git history. Almost all of the time, you want to use &lt;code&gt;git revert&lt;/code&gt; over &lt;code&gt;git reset&lt;/code&gt;, but there are exceptions. You can pretty safely use &lt;code&gt;git reset&lt;/code&gt; if you are working locally and the changes to the commit history will not affect anyone else that may be working on the branch you will be changing.&lt;/p&gt;




&lt;h2&gt;
  
  
  Fetch/Pull
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Fetch
&lt;/h3&gt;

&lt;p&gt;Fetching retrieves any changes from the remote and puts them in the local repository. It does not apply these changes to any files and, as such, doesn't alter any work that you may have in a given file. For example, if you're working in a file called &lt;code&gt;Button.tsx&lt;/code&gt; and you've made changes to 30 lines and then perform a &lt;code&gt;git fetch&lt;/code&gt; and another 20 lines have been changed in that file on the remote, you will now have those new lines, but you will not have them moved into your local file until you either choose to &lt;code&gt;git merge&lt;/code&gt; or &lt;code&gt;git rebase&lt;/code&gt;. This is preferable to &lt;code&gt;git pull&lt;/code&gt; as it gives you options.&lt;/p&gt;

&lt;h3&gt;
  
  
  Speaking of...
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;git pull&lt;/code&gt; on the other hand combines the commands &lt;code&gt;git fetch&lt;/code&gt; and &lt;code&gt;git merge&lt;/code&gt;. This is more dangerous because you may end up with merge conflicts that you do not anticipate and give you no way to deal with them other than fixing the merge and making a new commit. (note: the new commit is the problem albeit not a horrible one if you stick to the rule of doing a clean-up rebase before pushing)&lt;/p&gt;

&lt;h3&gt;
  
  
  Tips
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It is generally a good idea to use &lt;code&gt;git fetch&lt;/code&gt; alongside &lt;code&gt;git rebase&lt;/code&gt; which will come later. A colleague on a previous project got me in the habit of doing a &lt;code&gt;git fetch&lt;/code&gt; followed by a &lt;code&gt;git rebase&lt;/code&gt; every morning from our development branch to our feature branches. (the development branch is the one we would make PRs to from our feature branches). This is a tremendous help because it severely cuts down on merge conflicts later on when you PR said feature branch as you've already worked through any file changes in much smaller chunks. (At least most of the time...)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;git checkout origin/&amp;lt;branch-name&amp;gt;&lt;/code&gt; after using &lt;code&gt;git fetch&lt;/code&gt; to take a look at changes before rebasing. This can give you a good idea of any conflicts you may be fixing ahead of time and mitigating them in your code first. An ounce of prevention is worth a pound of cure.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Feature Branches
&lt;/h2&gt;

&lt;p&gt;I've mentioned feature branches. So a quick aside on what I mean. The concept of feature branches comes from trunk-based development. (note: I'm not going to be going into detail about that as it is extensive. But you can read more about it &lt;a href="https://semaphoreci.medium.com/trunk-based-development-the-key-to-better-and-faster-software-577a76fad3cf" rel="noopener noreferrer"&gt;here&lt;/a&gt; if you'd like.)&lt;/p&gt;

&lt;p&gt;Feature branches are short lived branches that only exist for the duration of a feature's development. Once the given feature is done, the branch is merged back into the main branch and then deleted. This process usually includes a code review before merging back into the main branch.&lt;/p&gt;

&lt;p&gt;This is the &lt;strong&gt;very&lt;/strong&gt; short version of how feature branches work. Feature branches are useful because they prevent developers from working on the same branch while making the new features. This is a good work flow because it prevents developers doing a bunch of work on one branch all at the same time. It is a very important topic when working with teams and I encourage you to seek out more information about it and talk to your fellow developers about best practices.&lt;/p&gt;




&lt;h2&gt;
  
  
  Rebasing
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Golden Rule:&lt;/strong&gt; Don't rebase if other people are working with your branch! Since rebasing creates new commits that are identical to the commits you had previously, it does remove the commits that were in place. &lt;strong&gt;BUT&lt;/strong&gt;, to reiterate, if you are using feature branches properly, this should never become an issue. Don't share your branches. Covet them. You are Smeegle, it is your precious ring. Don't merge it until it is done. Once a branch is merged, work should not be done on the feature. If work does need to be done, log a bug or new feature.&lt;/p&gt;

&lt;p&gt;Rebasing is essentially a way to put your feature branch at the end of the current branch instead of dealing with merges intermittently in that branch. The best way to think of this is in comparison to merging. Imagine you are working on a code base with a team of developers and you want to keep in sync with the main branch once a day (a very typical workflow). You can do this by pulling down the main branch each morning and then merging it with your feature and then cleaning up any subsequent changes. The issue with this practice is that the merges then muddy up your branch with commits that do nothing other than get the most current version of the development branch.&lt;/p&gt;

&lt;p&gt;On the other hand, if you do the same practice with rebase, you are simply updating your branch with the changes and shifting where your changes exist in relation to the current HEAD of the main branch. Which keeps things a lot cleaner and doesn't muddy up your commit history.&lt;/p&gt;

&lt;h2&gt;
  
  
  Interactive Rebasing
&lt;/h2&gt;

&lt;p&gt;Interactive rebasing is the process by which you can alter commits before they are remade by &lt;code&gt;git rebase&lt;/code&gt;. To do this we use the command &lt;code&gt;git rebase -i [&amp;lt;branch-name&amp;gt;] [&amp;lt;HEAD-#]&amp;gt;&lt;/code&gt;. Notice that both the branch name and number of commits is optional. But one or both is highly recommended. Now what can you do with it?&lt;/p&gt;

&lt;h3&gt;
  
  
  Rewording
&lt;/h3&gt;

&lt;p&gt;You can use rebase to reword commit messages before git replaces that commit. This is especially useful with hindsight because you might have a better idea of what that commit was actually doing with respect to the finished work.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fixing Up and Squashing
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;fixup&lt;/code&gt; gives you the ability to squash commits into one another but also gives you the ability to give a new commit name if you'd like. While &lt;code&gt;squash&lt;/code&gt; will just fold commits into the previous commit without giving you the rename option. Opt for &lt;code&gt;fixup&lt;/code&gt; so you don't have to remember more keywords and they do the same thing.&lt;/p&gt;

&lt;p&gt;Both of these maintain the code changes from removed commits. They just clean up history.&lt;/p&gt;

&lt;h3&gt;
  
  
  Drop
&lt;/h3&gt;

&lt;p&gt;This is dangerous. It gets rid of the commit and any changes in it. It's like it never happened.&lt;/p&gt;




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

&lt;p&gt;Hopefully these tips can help you use git a little more efficiently. Git is an amazing tool and one that we as developers should be using as ambitiously as possible. Thanks for reading!&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
    </item>
    <item>
      <title>Integrating MUI Button with React Router Link in React Applications</title>
      <dc:creator>Don Hamilton III</dc:creator>
      <pubDate>Wed, 07 Jun 2023 17:35:00 +0000</pubDate>
      <link>https://dev.to/donhamiltoniii/integrating-mui-button-with-react-router-link-in-react-applications-ij6</link>
      <guid>https://dev.to/donhamiltoniii/integrating-mui-button-with-react-router-link-in-react-applications-ij6</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In modern web development, particularly in React applications, it's often necessary to combine UI components with navigation functionality. Material-UI (MUI), a popular React UI framework, offers a comprehensive set of components that are both functional and aesthetically pleasing. React Router, on the other hand, is a standard library for routing in React. Integrating MUI's Button component with React Router's Link component allows developers to create buttons that not only look good but also facilitate seamless navigation. This article will guide you through the process of combining these two powerful tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before diving into the integration, ensure that you have the following prerequisites in your React project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React and React DOM&lt;/li&gt;
&lt;li&gt;Material-UI (MUI)&lt;/li&gt;
&lt;li&gt;React Router&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can install Material-UI and React Router via npm:&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; @mui/material @emotion/react @emotion/styled npm &lt;span class="nb"&gt;install &lt;/span&gt;react-router-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Basic Integration
&lt;/h2&gt;

&lt;p&gt;To start, we'll integrate a basic MUI Button with React Router's Link. Here's a simple example:&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="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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Link&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-router-dom&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;Button&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;@mui/material/Button&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;const&lt;/span&gt; &lt;span class="nx"&gt;MyButtonLink&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/your-path"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Navigate
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&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;In this code snippet, the &lt;code&gt;Button&lt;/code&gt; component from MUI is combined with the &lt;code&gt;Link&lt;/code&gt; component from React Router using the &lt;code&gt;component&lt;/code&gt; prop of the &lt;code&gt;Button&lt;/code&gt;. The &lt;code&gt;to&lt;/code&gt; prop specifies the navigation path, which is a key feature of the &lt;code&gt;Link&lt;/code&gt; component.&lt;/p&gt;

&lt;h2&gt;
  
  
  Styling the Button
&lt;/h2&gt;

&lt;p&gt;Material-UI provides extensive styling options. You can customize the appearance of the button to match your application's design. Here’s an example of a styled button:&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="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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Link&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-router-dom&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;Button&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;@mui/material/Button&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;makeStyles&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;@mui/styles&lt;/span&gt;&lt;span class="dl"&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;useStyles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;makeStyles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;linkButton&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;palette&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;primary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;white&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;amp;:hover&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="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;palette&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;primary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dark&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="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;MyStyledButtonLink&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;classes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useStyles&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="nc"&gt;Button&lt;/span&gt;
            &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
            &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/your-path"&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;classes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;linkButton&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            Navigate
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Button&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;In this example, we use &lt;code&gt;makeStyles&lt;/code&gt; to create custom styles and apply them to the button. This allows for a more personalized and consistent look throughout your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling Navigation Programmatically
&lt;/h2&gt;

&lt;p&gt;Sometimes, you might need to handle navigation programmatically, such as after a certain action is completed. Here’s how you can do it:&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="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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useHistory&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-router-dom&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;Button&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;@mui/material/Button&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;const&lt;/span&gt; &lt;span class="nx"&gt;MyProgrammaticButton&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;history&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useHistory&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;handleNavigation&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="c1"&gt;// Perform some action&lt;/span&gt;
        &lt;span class="nx"&gt;history&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/your-path&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="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="nc"&gt;Button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleNavigation&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Navigate&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Button&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;In this example, the &lt;code&gt;useHistory&lt;/code&gt; hook from React Router is used to navigate programmatically. The &lt;code&gt;history.push&lt;/code&gt; method is called within an event handler, allowing for more complex navigation logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Combining with Other MUI Components
&lt;/h2&gt;

&lt;p&gt;Material-UI's ecosystem is vast, and you can integrate the Button with other components like Icons, Toolbars, or Drawers. Here's an example with an Icon:&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="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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Link&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-router-dom&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;Button&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;@mui/material/Button&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;ArrowForwardIcon&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;@mui/icons-material/ArrowForward&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;const&lt;/span&gt; &lt;span class="nx"&gt;MyIconButtonLink&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;
        &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/your-path"&lt;/span&gt;
        &lt;span class="na"&gt;startIcon&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;lt;&lt;/span&gt;&lt;span class="nc"&gt;ArrowForwardIcon&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Navigate
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&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 example demonstrates how to add an icon to your button, enhancing its visual appeal and user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced Navigation Patterns
&lt;/h2&gt;

&lt;p&gt;In more complex applications, you might have nested routes or need to pass state to the navigation. React Router's &lt;code&gt;Link&lt;/code&gt; component allows for these advanced patterns. For instance, you can pass state as follows:&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="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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Link&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-router-dom&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;Button&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;@mui/material/Button&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;const&lt;/span&gt; &lt;span class="nx"&gt;MyButtonWithState&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;
        &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/your-path&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;fromButton&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="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Navigate with State
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&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;In this example, the &lt;code&gt;to&lt;/code&gt; prop is an object that includes both the pathname and the state. This is particularly useful when you need to pass data to the route you are navigating to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessibility Considerations
&lt;/h2&gt;

&lt;p&gt;When integrating UI components, it's important to consider accessibility. Material-UI components are designed with accessibility in mind, but you should ensure that your navigation is also accessible. This includes proper labeling, keyboard navigation, and focus management. For instance, adding an &lt;code&gt;aria-label&lt;/code&gt; to your button can improve accessibility:&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;
    &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/your-path"&lt;/span&gt;
    &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Navigate to your path"&lt;/span&gt;
&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    Navigate
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Integrating MUI's Button with React Router's Link provides a powerful way to create navigable UI elements in your React applications. This combination allows you to leverage the aesthetics and functionality of MUI with the navigational capabilities of React Router, resulting in an efficient and user-friendly experience. By following the examples and patterns outlined in this article, you can effectively integrate these two technologies in your next React project. Remember to always consider customization and accessibility to create a more inclusive and engaging user interface.&lt;/p&gt;

</description>
      <category>react</category>
      <category>mui</category>
      <category>router</category>
    </item>
    <item>
      <title>How to Structure a React Project</title>
      <dc:creator>Don Hamilton III</dc:creator>
      <pubDate>Wed, 08 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/donhamiltoniii/how-to-structure-a-react-project-5f2</link>
      <guid>https://dev.to/donhamiltoniii/how-to-structure-a-react-project-5f2</guid>
      <description>&lt;p&gt;One of the biggest problems we face as developers is project or directory structure. It's important to have a set structure for your projects so that as they grow, your code is well organized and easy to navigate. I recently found a way to organize React projects that I personally believe is so good that I want to share it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclaimer: This sort of organization can be used in pretty much any project with minor changes based on the project.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here is the &lt;a href="https://github.com/donhamiltoniii/how-to-structure-react-apps" rel="noopener noreferrer"&gt;repo&lt;/a&gt; if you want to explore everything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Components
&lt;/h2&gt;

&lt;p&gt;Starting at the component level, what I like to do is continue to use principles of OOP in all of my JS/TS applications. But This doesn't mean we have to use Classes, Methods, and Properties. If you would like to do that and create instances in a more traditional way, that's fine. But I think that it ignores all of the great things that we get from modern JS/TS. We can still follow SOLID principles without Classes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;component
  |-- component.tsx
  |-- hooks.ts
  |-- index.ts
  |-- styles.css
  |-- test.tsx
  |-- utils.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do each of these files do?&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;component.tsx&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Houses everything that is going to be rendered on screen by React. This file should contain as little logic as possible. If you can eliminate it entirely, all the better. Obviously that's not always popular but it should be the goal to keep the component as close to just markup as possible.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;hooks.ts&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;For any hooks in the component that are only used in this component. Any hooks that are shared with other components should be pulled up higher into a hooks directory at the root directory or &lt;code&gt;src&lt;/code&gt; depending on how your project is structured.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;index.ts&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Is solely our public interface for our component. Anything meant to be exported from this component gets exported from here. For example:&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="o"&gt;*&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;./component&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;Those sorts of exports are all that we include here&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;styles.css&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Should be fairly self explanitory. This is where we keep styles related to our component. This can also be a JS/TS file if you're using styled components or SASS or anything else so long as it's related to styling.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;test.tsx&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Is where we house the unit tests for our component.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;utils.ts&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Should contain utility functions related specifically to this component. Similar to the hooks file, anything that would be shared between components&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Accessing Next Data in Browser</title>
      <dc:creator>Don Hamilton III</dc:creator>
      <pubDate>Wed, 08 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/donhamiltoniii/accessing-next-data-in-browser-2no8</link>
      <guid>https://dev.to/donhamiltoniii/accessing-next-data-in-browser-2no8</guid>
      <description>&lt;p&gt;Today's is just a quick post of a discovery from a colleague. On the project that I'm currently assigned to, we are using NextJS to build some pretty amazing tech. One thing that we are constantly running up against is checking the data that we are receiving from one of the handful of APIs from which we are sourcing.&lt;/p&gt;

&lt;p&gt;Usually this involves all sorts of looking around inside of the network tab or console logging or all kinds of other work-around, hacky shit to see wtf we're getting. Which is both just bad form and, in most cases, ineffective.&lt;/p&gt;

&lt;p&gt;Until this wonderful, beautiful, simple, little one line of code came into all of our lives.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;__NEXT_DATA__&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 turns out that Next provides you the data that is being provided as props to the page in a serialized JSON object. Just another reason to love tf out of this framework. Here's an example payload that I get from my recipe site:&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="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"props"&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;"pageProps"&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;"recipes"&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="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bacon Wrapped Jalapeño Poppers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"prepTime"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"15 minutes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"cookTime"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"15 minutes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"servings"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"imgUrl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/img/jalapeno-poppers.jpg"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Jalapeños stuffed with cheese and wrapped with bacon."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"notes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Mad easy. Mad delicious. Perfect side dish."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"tags"&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="s2"&gt;"keto"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"jalapeño"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"cheese"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"cream cheese"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"bacon"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"appetizer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"side dish"&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;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;### Ingredients&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;- 8 Jalapeños, hollowed&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;- 8oz Cream Cheese&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;- 8oz shredded cheese of your choice&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;- 8 slices bacon&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;### Instructions&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;1. Cut a &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;T&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; into one side of your Jalapeños and scoop out the seeds.&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;1. In a bowl, mix cream cheese and shredded cheese until throughly mixed.&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;1. Preheat air frier for 10 minutes at 400°&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;1. Stuff each pepper with cheese mixture and wrap with one slice of bacon. Wrap the ends of the bacon underneath so they stay together.&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;1. Cook for 15 minutes at 350°&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;1. Eat them all in one sitting.&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&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;"slug"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"bacon-wrapped-jalapeño-poppers"&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="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;"__N_SSG"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&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;"page"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&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;"query"&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;"buildId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"development"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"isFallback"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"gsp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scriptLoader"&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="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;I truncated the recipe list for readability but you get the idea. Look at how easy and pretty that is! Keep this in mind whenever you're dealing with Next data. This is a game changer folx.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Proper (Re)Factoring</title>
      <dc:creator>Don Hamilton III</dc:creator>
      <pubDate>Wed, 08 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/donhamiltoniii/proper-refactoring-4ic4</link>
      <guid>https://dev.to/donhamiltoniii/proper-refactoring-4ic4</guid>
      <description>&lt;p&gt;Don't factor your code too early! There are plenty of organizational patterns that are essentially universal in an application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Having a &lt;code&gt;src&lt;/code&gt; directory&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;components&lt;/code&gt; - React/Next&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;utils&lt;/code&gt; - every project&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;routes&lt;/code&gt;/&lt;code&gt;views&lt;/code&gt; - web anything&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These will &lt;em&gt;probably&lt;/em&gt; exist in all of your applications/projects/whatever. Dont be afraid of using them. But let your applicaiton be abstract in the beginning. Don't rush to set a structure for how things should be organized, what should constitues a module, what should be a class (or shouldn't), making hooks, making utilities, etc. Just write the code, make the application work, WRITE THE TESTS (re-read that 1000x, get it tattooed on your body, paint it on the walls. Please. Write. Tests.), write documentation, know what it all does.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🚨🚨🚨 BEFORE YOU COMMIT YOUR CODE!, REFACTOR!!! 🚨🚨🚨&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Or, when you do it the first time, factor. This is why testing is sooooo important. If you have tests in place for your application, you know that your code functions. If you break tests, you messed up. That's ok. You should mess up. That means you're making progress. Just make sure you don't leave anything messed up.&lt;/p&gt;

&lt;p&gt;This is the stage in the development process where you make sure things are organized properly. This is the part where you focus on &lt;strong&gt;CODE READABILITY&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Split logic out into the tiniest possible pieces. Make new functions/methods, organize modules differently, split things into utilities. But only in a way that makes sense. And let your code tell you what makes sense. Things to consider:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;WTF is this code doing? - Can you answer that quickly? Can you make a TikTok that would allow someone to confidently implement your function?&lt;/li&gt;
&lt;li&gt;Is this repetative? - Is this logic (Or similar logic) happening anywhere else? If so, combine it. Pull it into a function. Move that function up the directory tree wherever it makes sense.&lt;/li&gt;
&lt;li&gt;Is it verbose? - Can you clean it up at all? Are you over-engineering?&lt;/li&gt;
&lt;li&gt;Do my tests still reflect what I want them to? - This is &lt;em&gt;sort of&lt;/em&gt; an after refactoring thing. I say sort of because it very much &lt;strong&gt;IS&lt;/strong&gt; refactoring. But, refactoring your tests tend to happen after you refactor the corresponding code. For example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Code&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;camelCaseToCapitalSnakeCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;string&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;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;A-Z&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`_&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;letter&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="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Test&lt;/span&gt;
&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;camelCaseToCapitalSnakeCase&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;should convert string to capital snake case&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="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;testString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hereIsMyCamelCaseString&lt;/span&gt;&lt;span class="dl"&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;expected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;HERE_IS_MY_CAMEL_CASE_STRING&lt;/span&gt;&lt;span class="dl"&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;camelCaseToCapitalSnakeCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;testString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&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;REFACTOR&lt;/strong&gt;&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;// Code&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;camelToSnakeCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;string&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;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;A-Z&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`_&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;letter&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;capitalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;string&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;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCAse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Test&lt;/span&gt;
&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;camelToSnakeCase&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;should convert camel to snake case&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="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;testString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hereIsMyCamelCaseString&lt;/span&gt;&lt;span class="dl"&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;expected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;here_is_my_camel_case_string&lt;/span&gt;&lt;span class="dl"&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;camelToSnakeCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;testString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&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="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;capitalize&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;should capitalize given string&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="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;testString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;example&lt;/span&gt;&lt;span class="dl"&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;expected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;EXAMPLE&lt;/span&gt;&lt;span class="dl"&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;capitalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;testString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&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;While this refactoring essentially happens at the same time (or should), usually the work to the code is done, the initial test fails, the tests are updated to reflect the change to the code.&lt;/p&gt;

&lt;p&gt;Refactoring is such an important step in the development of a code base. Mostly because tech debt has a strange way of going unpaid. There are so many minor things that we convince ourselves as devs that we will come back to, or someone will, to "clean up" or "clarify". But that rarely happens. The reality of writing code, especially new code, is that you have more context right now than anyone else, including yourself in a month, is ever going to have again. You know exactly what problem you're trying to solve and why you're doing it the way that you are. So it is your responsibility to try to capture that as much as possible for people in the future, including you. So don't let deadlines get in the way of doing the right thing. Take the extra hour or 4 or 8 to make sure this step happens. Because if you're in an environment that tracks tech debt, great. But the harsh reality is that those tickets will probably get stale before they get played. So do the work now.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React 18 Third Party Component Rendering Issue</title>
      <dc:creator>Don Hamilton III</dc:creator>
      <pubDate>Wed, 08 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/donhamiltoniii/react-18-third-party-component-rendering-issue-2mec</link>
      <guid>https://dev.to/donhamiltoniii/react-18-third-party-component-rendering-issue-2mec</guid>
      <description>&lt;p&gt;If you ever run into a build error with any package that looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;12:06:28 PM: &lt;span class="nv"&gt;$ &lt;/span&gt;yarn build
12:06:28 PM: yarn run v1.22.10
12:06:28 PM: &lt;span class="nv"&gt;$ &lt;/span&gt;next build
12:06:28 PM: info  - Checking validity of types...
12:06:32 PM: Failed to compile.
12:06:32 PM:
12:06:32 PM: ./pages/_app.tsx:6:11
12:06:32 PM: Type error: &lt;span class="s1"&gt;'Component'&lt;/span&gt; cannot be used as a JSX component.
12:06:32 PM:   Its element &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="s1"&gt;'ReactElement&amp;lt;any, any&amp;gt; | Component&amp;lt;{}, any, any&amp;gt; | null'&lt;/span&gt; is not a valid JSX element.
12:06:32 PM:     Type &lt;span class="s1"&gt;'Component&amp;lt;{}, any, any&amp;gt;'&lt;/span&gt; is not assignable to &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="s1"&gt;'Element | ElementClass | null'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
12:06:32 PM:       Type &lt;span class="s1"&gt;'Component&amp;lt;{}, any, any&amp;gt;'&lt;/span&gt; is not assignable to &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="s1"&gt;'ElementClass'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
12:06:32 PM:         The types returned by &lt;span class="s1"&gt;'render()'&lt;/span&gt; are incompatible between these types.
12:06:32 PM:           Type &lt;span class="s1"&gt;'React.ReactNode'&lt;/span&gt; is not assignable to &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="s1"&gt;'import("/opt/build/repo/node_modules/@types/react-syntax-highlighter/node_modules/@types/react/index").ReactNode'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
12:06:32 PM:             Type &lt;span class="s1"&gt;'{}'&lt;/span&gt; is not assignable to &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="s1"&gt;'ReactNode'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
12:06:32 PM:   4 |
12:06:32 PM:   5 | &lt;span class="nb"&gt;export &lt;/span&gt;default &lt;span class="k"&gt;function &lt;/span&gt;MyApp&lt;span class="o"&gt;({&lt;/span&gt; Component, pageProps &lt;span class="o"&gt;}&lt;/span&gt;: AppProps&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
12:06:32 PM: &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 6 |   &lt;span class="k"&gt;return&lt;/span&gt; &amp;lt;Component &lt;span class="o"&gt;{&lt;/span&gt;...pageProps&lt;span class="o"&gt;}&lt;/span&gt; /&amp;gt;&lt;span class="p"&gt;;&lt;/span&gt;
12:06:32 PM:     |           ^
12:06:32 PM:   7 | &lt;span class="o"&gt;}&lt;/span&gt;
12:06:32 PM:   8 |
12:06:32 PM: error Command failed with &lt;span class="nb"&gt;exit &lt;/span&gt;code 1. &lt;span class="o"&gt;(&lt;/span&gt;https://ntl.fyi/exit-code-1&lt;span class="o"&gt;)&lt;/span&gt;
12:06:32 PM: info Visit https://yarnpkg.com/en/docs/cli/run &lt;span class="k"&gt;for &lt;/span&gt;documentation about this command.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The current fix is to add the following to your &lt;code&gt;package.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json-doc"&gt;&lt;code&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"resolutions"&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;"@types/react"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"17.0.40"&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="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Base Path in TypeScript</title>
      <dc:creator>Don Hamilton III</dc:creator>
      <pubDate>Sat, 04 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/donhamiltoniii/base-path-in-typescript-128</link>
      <guid>https://dev.to/donhamiltoniii/base-path-in-typescript-128</guid>
      <description>&lt;p&gt;Whenever working in TypeScript, we deal with importing and exporting modules in our project. This quick post is just a reminder/tutorial for how to set up a base path so that we may reference these modules in a more organized fashion.&lt;/p&gt;

&lt;p&gt;Let's begin by creating a new project. We could just create a basic TypeScript app but let's create something a little more practical. We'll be creating a simple NextJS app that uses TypeScript. This is a pretty popular stack these days since it provides a full stack environment with the (current) most popular view library.&lt;/p&gt;

&lt;p&gt;To start, let's navigate to a directory to make our project and run 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;npx create-next-app base-path-example &lt;span class="nt"&gt;--ts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will build out a new Next app called &lt;code&gt;base-path-example&lt;/code&gt; with a directory structure that looks 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%2Fv47z3ss5cabfoodha97e.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%2Fv47z3ss5cabfoodha97e.png" alt="Base Path Example" width="594" height="954"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside of this project, we're going to include a deeply nested path by adding a few directories inside of pages.&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%2Fe89in6vvs8ltduib9o00.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%2Fe89in6vvs8ltduib9o00.png" alt="Base Path Pages" width="578" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is going to illustrate what happens when we have to bring in a component from way higher up in the directory tree. Here's what our deeply nested page looks like:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Counter&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="s2"&gt;../../../../components/counter&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="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;CounterPage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="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;Counter&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;p&gt;Notice that we're bringing in this &lt;code&gt;Counter&lt;/code&gt; component from the &lt;code&gt;components&lt;/code&gt; directory which is four levels up. While this certainly works, it's a little difficult to read and in an app with dozens, or even hundreds of pages, these &lt;code&gt;../&lt;/code&gt; pieces get annoying to deal with.&lt;/p&gt;

&lt;p&gt;To solve this issue, we can make a quick and easy update to our &lt;code&gt;tsconfig.json&lt;/code&gt; file which will simplify our imports throughout our entire app. Inside of &lt;code&gt;tsconfig.json&lt;/code&gt;, 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="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;tsconfig.json&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="nl"&gt;"compilerOptions"&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="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"baseUrl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&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;"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;"@/*"&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/*"&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="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;This gives us a shorthand to reference the &lt;code&gt;src&lt;/code&gt; directory. So now on any of our imports, we can just start with &lt;code&gt;@&lt;/code&gt;. Now we can revisit that deeply nested page and make the following change:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Counter&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="s2"&gt;@/components/counter&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="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;CounterPage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="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;Counter&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;p&gt;Now we can reference all directories and files relative to the &lt;code&gt;src&lt;/code&gt; directory! This avoids all of the backtracking with &lt;code&gt;../&lt;/code&gt;! As small of a change as this may be, it will save TONS of time with imports and help your code look a lot cleaner in the process.&lt;/p&gt;

&lt;h2&gt;
  
  
  SIDE NOTE FOR FULL-STACK/API PROJECTS
&lt;/h2&gt;

&lt;p&gt;If you are building something with &lt;code&gt;ts-node&lt;/code&gt; or &lt;code&gt;nodemon&lt;/code&gt;, you also need to follow &lt;a href="https://typestrong.org/ts-node/docs/paths/" rel="noopener noreferrer"&gt;this section&lt;/a&gt; of the &lt;code&gt;ts-node&lt;/code&gt; docs.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>CSS Centering</title>
      <dc:creator>Don Hamilton III</dc:creator>
      <pubDate>Sat, 04 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/donhamiltoniii/css-centering-5g7a</link>
      <guid>https://dev.to/donhamiltoniii/css-centering-5g7a</guid>
      <description>&lt;p&gt;Today we're going to be looking at the different ways in which you can center content in CSS. We're gonna go through a bit of a history lesson as well to illustrate just how amazing modern tools are in comparison to the shit we used to have to write as developers to achieve the same goal. We are going to be looking at examples of centering both horizontally and vertically but all of these examples can be used to accomplish each task individually.&lt;/p&gt;

&lt;p&gt;* &lt;em&gt;Only the SCSS related to positioning is included. You will see more in the CodePen.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/donhamiltoniii/embed/bGpxQKd?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Centering using &lt;code&gt;display: table&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Let's take a look at the code:&lt;/p&gt;

&lt;p&gt;HTML:&lt;br&gt;
&lt;/p&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;table&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"table-centering"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;tr&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"table-centering__row"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"table-centering__content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;:( why?&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SCSS:&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;.table-centering&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nt"&gt;__row&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;vertical-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&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;As we can see, this achieves what we want. But this is clunky and it violates a few golden rules. First of all, this isn't tabular data so our markup (HTML) isn't semantic. It's also violating separation of concerns as we're using our content layer to handle styling. In older web infrastructure, this method of styling isn't uncommon to see. Though it is &lt;em&gt;INCREDIBLY&lt;/em&gt; frowned upon. So, moving on to better options.&lt;/p&gt;

&lt;h3&gt;
  
  
  Centering using &lt;code&gt;transform&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Now we'll explore a better (still not best) option. This one came about once we got the &lt;code&gt;transform&lt;/code&gt; property available in browsers (2009ish). This is definitely a better way to achieve our centered goal than the previous as it allows us to semantically markup our content as well as abide by separation of concerns by keeping the positioning solely to the style (SCSS) layer. Let's take a look at the code and then go over the pros and cons:&lt;/p&gt;

&lt;p&gt;HTML:&lt;br&gt;
&lt;/p&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;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"transform-centering"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"transform-centering__content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;:| slightly less why?&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SASS:&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;.transform-centering&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nt"&gt;__content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;translateY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&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;The first notable difference here is the markup. We only have a containing element and a contained element. Honestly, this is all we should have since we're centering one thing inside of something else. Second, it's semantic. We have a &lt;code&gt;section&lt;/code&gt;, which is properly descriptive of what it is/does and the content is enclosed in a &lt;code&gt;p&lt;/code&gt; tag which also accurtately describes what we're dealing with. These might seem like trivial details, but I assure you, for many reasons, they are not. This will be beneficial to other developers looking at your code and it will be much more descriptive for screen readers and robots (read Google bots) crawling your page to index it inside of their search algorithms.&lt;/p&gt;

&lt;p&gt;Next, let's examine the styling. There are a few more lines of code here to achieve our goal, but what is better about this solution is that everything about the positioning is encapsulated in the style layer.&lt;/p&gt;

&lt;p&gt;What I personally dislike (you should too) about this method is that it forces us to alter the &lt;code&gt;position&lt;/code&gt; attribute of both of these elements. While this isn't strictly taboo, it can cause unforeseen consequences with other style rules. It is general best practice to avoid manipulating position, &lt;strong&gt;BUT&lt;/strong&gt;, this does work. The quick explanation is that we are pushing the paragraph 50% the width and height of the container. The problem is we are pushing relative to the top left corner of the contained element. So then we are manipulating the contained element to move half of its own width and height up and to the left respectively. In so doing, we center the paragraph in the section.&lt;/p&gt;

&lt;h3&gt;
  
  
  Centering using &lt;code&gt;flex&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Finally, we arrive at &lt;strong&gt;THE&lt;/strong&gt; definitive answer for centering in modern web development. The answer is for sure using Flexbox. We need look no further than the code to understand why:&lt;/p&gt;

&lt;p&gt;HTML:&lt;br&gt;
&lt;/p&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;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flexbox-centering"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flexbox-centering__content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;:) very much zero why?&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SCSS:&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;.flexbox-centering&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&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;So this technique combines all of the good parts of the previous examples while omitting all of the bad parts. First, our markup is succinct and semantic. Next, our styling is encapsulated and only needs 3 lines of code to work.&lt;/p&gt;

&lt;p&gt;This is partially why flexbox exists. It's all about positioning and ordering elements without having to worry about the content layer. This is exactly how we want our code to work. That is textbook definition of proper separation of concerns.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;BONUS&lt;/strong&gt; Centering using &lt;code&gt;grid&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;It is possible to center content inside of grid containers as well. Though, I would argue that you should use &lt;code&gt;flex&lt;/code&gt; by default, sometimes that adds superfluous code which should &lt;strong&gt;ALWAYS&lt;/strong&gt; be avoided if possible. So let's take a look at how we can achieve our goal in grid.&lt;/p&gt;

&lt;p&gt;HTML:&lt;br&gt;
&lt;/p&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;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-centering"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-centering__content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;:) very much zero why? #2&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SCSS:&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;.grid-centering&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;align-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="na"&gt;justify-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&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;Not much more to review here aside from the fact that we're using a different display value. The only notable difference here is the usage of &lt;code&gt;align-content&lt;/code&gt; and &lt;code&gt;justify-items&lt;/code&gt; as opposed to their Flexbox counterparts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;We've gone through a bit of a history lesson as far as how we deal with layout and positioning in our web sites/applications. The first two are here for historical reference only. Going forward, we should all be using Flexbox and Grid whenever we're dealing with layout and positioning.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
