<?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: Suraj Surve</title>
    <description>The latest articles on DEV Community by Suraj Surve (@s15raj).</description>
    <link>https://dev.to/s15raj</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%2F124425%2Ff49b9688-57e6-4b9a-ae0c-3ecbc86bbff7.jpeg</url>
      <title>DEV Community: Suraj Surve</title>
      <link>https://dev.to/s15raj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/s15raj"/>
    <language>en</language>
    <item>
      <title>Design/Architect  Components Structure in React.js?
</title>
      <dc:creator>Suraj Surve</dc:creator>
      <pubDate>Sun, 16 May 2021 14:12:53 +0000</pubDate>
      <link>https://dev.to/s15raj/design-architect-components-structure-in-react-js-40bk</link>
      <guid>https://dev.to/s15raj/design-architect-components-structure-in-react-js-40bk</guid>
      <description>&lt;p&gt;React.js has component based architecture. Developers community has embraced this kind of approach &amp;amp; that's why &lt;a href="https://www.freecodecamp.org/news/why-use-react-for-web-development/" rel="noopener noreferrer"&gt;React.js popularity&lt;/a&gt; gained over the years. &lt;/p&gt;

&lt;p&gt;One of the most challenging part in React.js is to design or architect component structure properly. It will help rendering components faster and efficiently. Also, it is easier for new developers to understand and make changes into components very easily.&lt;/p&gt;

&lt;p&gt;In this article, we will see how to find components in the prototype of website and how to structure them.&lt;/p&gt;

&lt;p&gt;Here is the website prototype where we list down entrepreneurs and search them by their name and birth year.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Find Components From Prototype
&lt;/h2&gt;

&lt;p&gt;Let's start with the Header.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Header&lt;/strong&gt; is our one of the component. In the header we have two more components. &lt;strong&gt;Logo&lt;/strong&gt; and  &lt;strong&gt;Logout&lt;/strong&gt;. So we have got the Three components till now. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1]&lt;/strong&gt; Header (Parent Component)&lt;br&gt;
&lt;strong&gt;2]&lt;/strong&gt; Logo (Child Component)&lt;br&gt;
&lt;strong&gt;3]&lt;/strong&gt; Logout (Child Component)&lt;/p&gt;

&lt;p&gt;Let's come to Filter area now.&lt;/p&gt;

&lt;p&gt;We have Filter below Header. &lt;strong&gt;Filter&lt;/strong&gt; can be one of the components. Filter has Two components in it. &lt;strong&gt;Year&lt;/strong&gt; and &lt;strong&gt;Search&lt;/strong&gt;. So we have got the Six components till now. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4]&lt;/strong&gt; Filter (Parent Component)&lt;br&gt;
&lt;strong&gt;5]&lt;/strong&gt; Year (Child Component)&lt;br&gt;
&lt;strong&gt;6]&lt;/strong&gt; Search (Child Component)&lt;/p&gt;

&lt;p&gt;Let's come to Profile area now.&lt;/p&gt;

&lt;p&gt;Here we can take &lt;strong&gt;Profile&lt;/strong&gt; as a parent component. It contains three child components. &lt;strong&gt;Profile Picture&lt;/strong&gt;, &lt;strong&gt;Bio&lt;/strong&gt; and &lt;strong&gt;Social Profiles&lt;/strong&gt;. So we have got the Ten components till now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7]&lt;/strong&gt; Profile (Parent Component)&lt;br&gt;
&lt;strong&gt;8]&lt;/strong&gt; Profile Picture (Child Component)&lt;br&gt;
&lt;strong&gt;9]&lt;/strong&gt; Bio (Child Component)&lt;br&gt;
&lt;strong&gt;10]&lt;/strong&gt; Social Profiles (Child Component)&lt;/p&gt;

&lt;p&gt;Let's come to Footer area now.&lt;/p&gt;

&lt;p&gt;We have footer as parent component and copyright information as child component. So we got Two components here. &lt;strong&gt;Footer&lt;/strong&gt; and &lt;strong&gt;Copywrite Info&lt;/strong&gt;. So we have got the twelve components till now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;11]&lt;/strong&gt; Footer (Parent Component)&lt;br&gt;
&lt;strong&gt;12]&lt;/strong&gt; Copywrite Info (Child Component)&lt;/p&gt;

&lt;p&gt;Great, We have almost found all the possible components for this application. Now, there is still one component we need and that is &lt;strong&gt;App&lt;/strong&gt; Component. App components will the topmost parent component. All the parent components above we found, will be the child components under App component.&lt;/p&gt;

&lt;p&gt;Here is the diagram representation of it.&lt;/p&gt;

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

&lt;p&gt;If you are aware of &lt;em&gt;one-way data flow&lt;/em&gt; in the React.js then from above diagram you can see that the Data, State and Behavior can flow from App component to it's child components.&lt;/p&gt;

&lt;p&gt;Each component has its own state and behavior that can be passed to it's child component(s).&lt;/p&gt;

&lt;p&gt;If you remove any of the child components from above then it is not going to affect other parts of the application.&lt;/p&gt;

&lt;p&gt;Also, you can make separate .js files for all the parent components. Like, App component should be in &lt;em&gt;app.js&lt;/em&gt; file and it's child components also can be in separate .js file (&lt;em&gt;header.js&lt;/em&gt;, &lt;em&gt;filter.js&lt;/em&gt;, &lt;em&gt;profile.js&lt;/em&gt; and &lt;em&gt;footer.js&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;Bottom child components (in green) can be in their parent component .js files. You don't need to make separate .js files for them because it will be difficult to maintain.&lt;/p&gt;

&lt;p&gt;As an application gets complex you will have to make some advance design patterns changes for components to make application fast and maintainable. BUT this is the basic way to start architect or design your components for a new application.  &lt;/p&gt;

&lt;p&gt;You can also learn how to &lt;a href="https://www.tutorialfunda.com/reactjs/setup-react-js-project-with-next-js-vs-code/" rel="noopener noreferrer"&gt;setup your first react.js project&lt;/a&gt; and start designing components shown above.&lt;/p&gt;

&lt;p&gt;Subscribe to my &lt;a href="https://www.tutorialfunda.com/blog/" rel="noopener noreferrer"&gt;blog&lt;/a&gt; &amp;amp; Follow me on &lt;a href="https://www.linkedin.com/in/suraj-surve/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; &amp;amp; &lt;a href="https://twitter.com/s15raj" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; &amp;amp; &lt;a href="https://www.facebook.com/suraj.surve.39/" rel="noopener noreferrer"&gt;Facebook&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>architecture</category>
      <category>design</category>
    </item>
  </channel>
</rss>
