<?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: MuhireIghor</title>
    <description>The latest articles on DEV Community by MuhireIghor (@muhireighor).</description>
    <link>https://dev.to/muhireighor</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%2F869120%2F6a9979c6-3e88-42b7-a9c6-cfedc88c37c9.jpeg</url>
      <title>DEV Community: MuhireIghor</title>
      <link>https://dev.to/muhireighor</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muhireighor"/>
    <language>en</language>
    <item>
      <title>Proper structure of a react application</title>
      <dc:creator>MuhireIghor</dc:creator>
      <pubDate>Mon, 05 Jun 2023 19:38:52 +0000</pubDate>
      <link>https://dev.to/muhireighor/proper-structure-of-a-react-application-57ce</link>
      <guid>https://dev.to/muhireighor/proper-structure-of-a-react-application-57ce</guid>
      <description>&lt;p&gt;Hello there,I am Muhire Ighor a react developer ,In this blog I will be talking about the proper structuring of a react application .&lt;br&gt;
Many people often face a problem of poor structuring of their react application code base.&lt;br&gt;
I have summarized this structure into about 7 main parts:&lt;br&gt;
&lt;strong&gt;Pages&lt;/strong&gt;,&lt;strong&gt;Components&lt;/strong&gt;,&lt;strong&gt;hooks&lt;/strong&gt;,&lt;strong&gt;utils&lt;/strong&gt;,&lt;strong&gt;layouts&lt;/strong&gt;,&lt;strong&gt;data&lt;/strong&gt;,&lt;strong&gt;context&lt;/strong&gt;,&lt;strong&gt;styles&lt;/strong&gt;,&lt;strong&gt;assets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As of the current version of react &lt;strong&gt;18.2&lt;/strong&gt;&lt;br&gt;
Every project is mainly wrapped in the src folder:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4ebfpZl3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qcysrgqn66hp9bfaoail.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4ebfpZl3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qcysrgqn66hp9bfaoail.png" alt="Image description" width="800" height="425"&gt;&lt;/a&gt;&lt;br&gt;
Above is the attached general react file structure&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Pages&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In the pages folder this is where you put the final page to be displayed in the browser on a certain endpoint:&lt;br&gt;
For example one may say a Home page at "localhost:3000"&lt;/p&gt;

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

&lt;p&gt;Then in the home page he/she may have the Navbar component ,then &lt;br&gt;
the Navbar component will go into the Components folder for allowing re usability across the application 🤪🤪.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Layout&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We may have like the Auth layout where as both the signup and signin may all have a footer so there is no use for repetition we can make an AuthLayout in the layout folder where by the use of the &lt;strong&gt;outlet component&lt;/strong&gt; from the "react-router-dom" ,the outlet component allows us to have various page views but with some common components according to the routes that is specified in the routing file as for my example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jfrfynWa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n821jm6nlb78bjo3u6lf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jfrfynWa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n821jm6nlb78bjo3u6lf.png" alt="Image description" width="800" height="383"&gt;&lt;/a&gt;&lt;br&gt;
You can observe that we have the HomeLayout component that is to accept a specific child according to the route where like for the main end point "/",&lt;br&gt;
we will have the MainComponent for the "/" endpoint,&lt;br&gt;
Contacts for the "/pages/contact" end point,&lt;br&gt;
and the Aboutus component for the "/pages/discover..." and then the Notfoundpage component for any of the routes that is not specified.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Hooks&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In the &lt;strong&gt;hooks&lt;/strong&gt; section we put there some custom functions that will be used in many of our components but using different arguments.&lt;br&gt;
In this section it is advisable to begin your function using the "&lt;strong&gt;use&lt;/strong&gt;"keyword eg:"useSignup"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--34JCxIeI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lb86trkozbxl2rip3ruz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--34JCxIeI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lb86trkozbxl2rip3ruz.png" alt="Image description" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Styles&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In the &lt;strong&gt;Styles&lt;/strong&gt; folder one puts his/her css stylings .&lt;/p&gt;

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

&lt;h2&gt;
  
  
  &lt;strong&gt;data&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In the data folder one may put the dummy data to be used in case he/she has not got active backend from which to fetch the data from.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Utils&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In the &lt;strong&gt;utils&lt;/strong&gt; folder we put there some functions to operate on some inputs like for my example I made a cash formatting function to format the currency for the products added on the cart.&lt;/p&gt;

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

</description>
      <category>react</category>
      <category>webdev</category>
      <category>structuring</category>
      <category>development</category>
    </item>
  </channel>
</rss>
