<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ayako on Medium]]></title>
        <description><![CDATA[Stories by Ayako on Medium]]></description>
        <link>https://medium.com/@ayako-dev?source=rss-447e99c96081------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qf74wyFHgsriSzj3n-Kesg.jpeg</url>
            <title>Stories by Ayako on Medium</title>
            <link>https://medium.com/@ayako-dev?source=rss-447e99c96081------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:16:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayako-dev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[“Level Up Your ReactJS Skills: 5 Best Practices for Developing High-Quality Applications”]]></title>
            <link>https://ayako-dev.medium.com/level-up-your-reactjs-skills-5-best-practices-for-developing-high-quality-applications-97ef473727e?source=rss-447e99c96081------2</link>
            <guid isPermaLink="false">https://medium.com/p/97ef473727e</guid>
            <category><![CDATA[development-and-growth]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ayako]]></dc:creator>
            <pubDate>Wed, 22 Feb 2023 17:33:57 GMT</pubDate>
            <atom:updated>2023-02-22T17:33:57.862Z</atom:updated>
            <content:encoded><![CDATA[<p>“Level Up Your ReactJS Skills: 5 Best Practices for Developing High-Quality Applications”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4a7jVw9OIZIRJ_ktE9c9Ug.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@kevnbhagat">Kevin Bhagat</a></figcaption></figure><p>ReactJS is a popular JavaScript library that’s used for building user interfaces. It provides a component-based approach to development, making it easier to build complex UIs. However, as with any technology, there are certain best practices that developers should follow to ensure that their code is efficient, maintainable, and scalable. In this regard, here are five best practices for ReactJS development.</p><p>Certainly, here are five best practices for ReactJS development:</p><ol><li><strong>Use Functional Components </strong><br>With the introduction of React hooks, functional components have become the preferred way of building components in React. Functional components are simpler, easier to reason about, and can be more performant than class components.</li><li><strong>Keep Components Small and Focused</strong><br>One of the core principles of React is the idea of building small, reusable components. Each component should be responsible for a specific task and should not have any unrelated functionality.</li><li><strong>Use JSX</strong><br>JSX is a syntax extension that allows you to write HTML-like code directly in your JavaScript. This can make your code more readable and can help to catch errors at compile time.</li><li><strong>Embrace Immutability</strong><br>In React, it’s important to keep your data immutable, meaning that once a value is set, it cannot be changed. This makes it easier to reason about your code and can help to prevent bugs caused by unintended changes to data.</li><li><strong>Use a State Management Library</strong><br>As your application grows in size and complexity, it can become more difficult to manage your application state. Using a state management library like Redux or MobX can make it easier to manage your application state and can help to prevent common issues like race conditions and inconsistent data.</li></ol><p>Following these best practices can help developers create better ReactJS applications that are easier to maintain, debug, and scale. While these are by no means an exhaustive list of best practices for ReactJS development, they provide a solid foundation for building high-quality, maintainable code. By staying informed and implementing these practices, developers can ensure that their ReactJS applications are performant, reliable, and easy to work with.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97ef473727e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Filter Architecture In Your Front-end Project]]></title>
            <link>https://medium.com/geekculture/filter-architecture-in-your-front-end-project-7e4d3d7ee957?source=rss-447e99c96081------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e4d3d7ee957</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Ayako]]></dc:creator>
            <pubDate>Wed, 10 Nov 2021 19:03:16 GMT</pubDate>
            <atom:updated>2021-11-10T19:03:16.948Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tOO04G24d1YU0zzZnmkGOQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@weareambitious?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ambitious Creative Co. — Rick Barrett</a> on <a href="https://unsplash.com/s/photos/net?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>When you’re working on a medium-to-large scale project, you probably need to handle many API requests and response. You send a request body to the backend server, and the server returns back the response. This is a very common way of fetching data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*q5rt6NhcEo_0aIy0xap_KQ.png" /><figcaption>Normal Fetching Process</figcaption></figure><p>During this process, sometimes you will notice that the returned response might contain unnecessary data, and the data format doesn’t compatible or align with your front-end project standard. For example, mismatched parameter keys, non-identical naming convention, different object format etc. While all these “unfiltered” data gonna becomes an unintentional culprit that creates bugs and increase your technical debt.</p><p>In this case, usually you will spend time keep debugging and fixing it until your component displays the response correctly. But, have you thought about WHY? Why all these bugs will happen? Why you’re the one who keeps dealing with it?</p><p>If you’ve already have a set of code standard in your front-end project, means you have a guideline to follow. You can prevent the API responses from messing up with your codes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g3X6ay784N5-nQUiECowbQ.jpeg" /><figcaption>Aigues-Mortes city walls, France</figcaption></figure><p>Alright, imagine you’re the lord of the land, and you set up a checkpoint at the gate of the city. You need to know who is passing through the city, and they can come in only with certain rights and permission.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0qF59S9T1zCRgrAjTPKNHg.png" /><figcaption>Filtered Fetching Process</figcaption></figure><p>So, here’s comes the <strong>Filter Architecture</strong>. It acts as a <strong>middle-net</strong> that stays between the process of requesting &amp; fetching API response. Basically, you will modify your request and response body, can also call it as <strong><em>payload, </em></strong>during the data fetching process.</p><p>When the server returns the response data, you will filter the original API data according to your requirement. After that, stores the formatted data into your Redux or any other state management place on your project.</p><blockquote><strong><em>As a reminder, Filter it before storing.</em></strong></blockquote><p>For example, you’re using camelCase as the keys you front-end payload, but the back-end receives snack_caseas the keys. Then, in this case, you gonna format your payload by renaming the keys in order to match the back-end requirement. You may consider creating a global function that performs this logic change. Vice-versa, this same goes to the returned API response as well. You can convert the key names in the response and make it to match with your front-end standard. Thus, your front end code will always keep its standard for better maintainability, easier debugging &amp; lesser bugs.</p><p>On top of that, you can also filter out the unnecessary data when you received the returned response from the API. For example, you have a section that consists of multiple cards that displays books information in your page. Each card will will only display the book’s name, cover, author and publisher. However, the API returns redundancy information like a service bean, author’s notes, publisher’s notes, etc. All these unneeded info can be filtered out &amp; re-format before passing it to your card components.</p><h4>Tips on Filtering</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKAaoAMlFtMawJYMe4IXNw.jpeg" /></figure><p>Let’s take the book infos <em>(mentioned above) </em>as a demo case. Below is an example of renaming keys and removing unwanted data inside the book array<em> </em>using map() :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BYgtuE8JAr9qqcF-K0igbQ.png" /><figcaption>Visual Studio Code | <a href="https://marketplace.visualstudio.com/items?itemName=AyakoSky.fluffy-theme">Fluffy Theme</a></figcaption></figure><p>In the example above, you can see that I only take the data needed for my card components. And then, I use get() to retrieve the value from the original array. Here’s how’s get() works:</p><pre>get(object, &#39;your object path, can be nested one&#39;, &#39;fallback value&#39;)</pre><p>If the API data passes back empty value in any of the keys above, it will use the fallback value that I assigned by default. I assigned an empty string here. You may assign any default fallback value according to your need. This method helps reducing bugs &amp; errors if you use it wisely. For more information, you can read the official docs of <a href="https://lodash.com/docs/4.17.15#get">Lodash</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5F0m0SVSAwWzrok8rIAW9Q.png" /></figure><p>Thanks for reading! Do give me some claps if you find this article helpful! Happy coding &amp; Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e4d3d7ee957" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/filter-architecture-in-your-front-end-project-7e4d3d7ee957">Filter Architecture In Your Front-end Project</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Filter Architecture]]></title>
            <link>https://ayako-dev.medium.com/what-is-filter-architecture-6dc4dad129f5?source=rss-447e99c96081------2</link>
            <guid isPermaLink="false">https://medium.com/p/6dc4dad129f5</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ayako]]></dc:creator>
            <pubDate>Tue, 09 Nov 2021 17:27:52 GMT</pubDate>
            <atom:updated>2021-11-09T17:27:52.416Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to Use Filter Architecture for Your Frontend Application</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GOIeYiwurYkfKVm4_pZo2g.jpeg" /></figure><p>When you’re working on a medium-to-large scale project, you probably need to handle many API requests and responses. You send a request body to the backend server, and the server returns back the response. This is a very common way of fetching data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*q5rt6NhcEo_0aIy0xap_KQ.png" /><figcaption>Normal Fetching Process</figcaption></figure><p>During this process, sometimes you will notice that the returned response might contain unnecessary data, and the data format doesn’t compatible or aligned with your front-end project standard. For example, mismatched parameter keys, non-identical naming conventions, different object formats etc. While all these “unfiltered” data gonna become an unintentional culprit that creates bugs and increases your technical debt.</p><p>In this case, usually, you will spend time keep debugging and fixing it until your component displays the response correctly. But, have you thought about WHY? Why all these bugs will happen? Why you’re the one who keeps dealing with it?</p><p>If you’ve already had a set of code standards in your front-end project, means you have a guideline to follow. You can prevent the API responses from messing up with your codes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g3X6ay784N5-nQUiECowbQ.jpeg" /><figcaption>Aigues-Mortes city walls, France</figcaption></figure><p>Alright, imagine you’re the lord of the land, and you set up a checkpoint at the gate of the city. You need to know who is passing through the city, and they can come in only with certain rights and permission.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0qF59S9T1zCRgrAjTPKNHg.png" /><figcaption>Filtered Fetching Process</figcaption></figure><p>So, here comes the <strong>Filter Architecture</strong>. It acts as a <strong>middle-net</strong> that stays between the process of requesting &amp; fetching API responses. Basically, you will modify your request and the response body can also call it a <strong><em>payload,</em></strong> during the data fetching process.</p><p>When the server returns the response data, you will filter the original API data according to your requirement. After that, stores the formatted data into your Redux or any other state management place on your project.</p><blockquote><strong><em>As a reminder, Filter it before storing.</em></strong></blockquote><p>For example, you’re using camelCase as the keys your front-end payload, but the back-end receives snack_caseas the keys. Then, in this case, you gonna format your payload by renaming the keys in order to match the back-end requirement. You may consider creating a global function that performs this logic change. Vice-versa, this same goes to the returned API response as well. You can convert the key names in the response and make it match your front-end standard. Thus, your front end code will always keep its standard for better maintainability, easier debugging &amp; lesser bugs.</p><p>On top of that, you can also filter out the unnecessary data when you received the returned response from the API. For example, you have a section that consists of multiple cards that display books information on your page. Each card will only display the book’s name, cover, author and publisher. However, the API returns redundancy information like a service bean, author’s notes, publisher’s notes, etc. All this unneeded info can be filtered out &amp; re-format before passing it to your card components.</p><h3>Tips on Filtering</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKAaoAMlFtMawJYMe4IXNw.jpeg" /></figure><p>Let’s take the book Infos <em>(mentioned above) </em>as a demo case. Below is an example of renaming keys and removing unwanted data inside the book array<em> </em>using map() :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BYgtuE8JAr9qqcF-K0igbQ.png" /><figcaption>Visual Studio Code | <a href="https://marketplace.visualstudio.com/items?itemName=AyakoSky.fluffy-theme">Fluffy Theme</a></figcaption></figure><p>In the example above, you can see that I only take the data needed for my card components. And then, I use get() to retrieve the value from the original array. Here’s how’s get() works:</p><pre>get(object, &#39;your object path, can be nested one&#39;, &#39;fallback value&#39;)</pre><p>If the API data passes back an empty value in any of the keys above, it will use the fallback value that I assigned by default. I assigned an empty string here. You may assign any default fallback value according to your need. This method helps reduce bugs &amp; errors if you use it wisely. For more information, you can read the official docs of <a href="https://lodash.com/docs/4.17.15#get">Lodash</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5F0m0SVSAwWzrok8rIAW9Q.png" /></figure><p>Thanks for reading! Do give me some claps if you find this article helpful! Happy coding &amp; Cheers!</p><h3>Learn More</h3><ul><li><a href="https://enlear.academy/breaking-a-large-angular-app-into-microfrontends-fb8f985d549f">How to Build Microfrontends with Angular</a></li><li><a href="https://enlear.academy/top-5-javascript-module-bundlers-for-2021-e6fe17657fb">Top 5 JavaScript Module Bundlers for 2021</a></li><li><a href="https://enlear.academy/top-web-development-trends-in-2021-7c76ab1276dd">Top Web Development Trends in 2021</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6dc4dad129f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Filter Architecture In Your Front-end Project]]></title>
            <link>https://itnext.io/filter-architecture-in-your-front-end-project-6bd9108a8d7f?source=rss-447e99c96081------2</link>
            <guid isPermaLink="false">https://medium.com/p/6bd9108a8d7f</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Ayako]]></dc:creator>
            <pubDate>Tue, 09 Nov 2021 08:03:27 GMT</pubDate>
            <atom:updated>2021-11-09T08:03:27.586Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tOO04G24d1YU0zzZnmkGOQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@weareambitious?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ambitious Creative Co. — Rick Barrett</a> on <a href="https://unsplash.com/s/photos/net?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>When you’re working on a medium-to-large scale project, you probably need to handle many API requests and response. You send a request body to the backend server, and the server returns back the response. This is a very common way of fetching data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*q5rt6NhcEo_0aIy0xap_KQ.png" /><figcaption>Normal Fetching Process</figcaption></figure><p>During this process, sometimes you will notice that the returned response might contain unnecessary data, and the data format doesn’t compatible or align with your front-end project standard. For example, mismatched parameter keys, non-identical naming convention, different object format etc. While all these “unfiltered” data gonna becomes an unintentional culprit that creates bugs and increase your technical debt.</p><p>In this case, usually you will spend time keep debugging and fixing it until your component displays the response correctly. But, have you thought about WHY? Why all these bugs will happen? Why you’re the one who keeps dealing with it?</p><p>If you’ve already have a set of code standard in your front-end project, means you have a guideline to follow. You can prevent the API responses from messing up with your codes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g3X6ay784N5-nQUiECowbQ.jpeg" /><figcaption>Aigues-Mortes city walls, France</figcaption></figure><p>Alright, imagine you’re the lord of the land, and you set up a checkpoint at the gate of the city. You need to know who is passing through the city, and they can come in only with certain rights and permission.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0qF59S9T1zCRgrAjTPKNHg.png" /><figcaption>Filtered Fetching Process</figcaption></figure><p>So, here’s comes the <strong>Filter Architecture</strong>. It acts as a <strong>middle-net</strong> that stays between the process of requesting &amp; fetching API response. Basically, you will modify your request and response body, can also call it as <strong><em>payload, </em></strong>during the data fetching process.</p><p>When the server returns the response data, you will filter the original API data according to your requirement. After that, stores the formatted data into your Redux or any other state management place on your project.</p><blockquote><strong><em>As a reminder, Filter it before storing.</em></strong></blockquote><p>For example, you’re using camelCase as the keys you front-end payload, but the back-end receives snack_caseas the keys. Then, in this case, you gonna format your payload by renaming the keys in order to match the back-end requirement. You may consider creating a global function that performs this logic change. Vice-versa, this same goes to the returned API response as well. You can convert the key names in the response and make it to match with your front-end standard. Thus, your front end code will always keep its standard for better maintainability, easier debugging &amp; lesser bugs.</p><p>On top of that, you can also filter out the unnecessary data when you received the returned response from the API. For example, you have a section that consists of multiple cards that displays books information in your page. Each card will will only display the book’s name, cover, author and publisher. However, the API returns redundancy information like a service bean, author’s notes, publisher’s notes, etc. All these unneeded info can be filtered out &amp; re-format before passing it to your card components.</p><h4>Tips on Filtering</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKAaoAMlFtMawJYMe4IXNw.jpeg" /></figure><p>Let’s take the book infos <em>(mentioned above) </em>as a demo case. Below is an example of renaming keys and removing unwanted data inside the book array<em> </em>using map() :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BYgtuE8JAr9qqcF-K0igbQ.png" /><figcaption>Visual Studio Code | <a href="https://marketplace.visualstudio.com/items?itemName=AyakoSky.fluffy-theme">Fluffy Theme</a></figcaption></figure><p>In the example above, you can see that I only take the data needed for my card components. And then, I use get() to retrieve the value from the original array. Here’s how’s get() works:</p><pre>get(object, &#39;your object path, can be nested one&#39;, &#39;fallback value&#39;)</pre><p>If the API data passes back empty value in any of the keys above, it will use the fallback value that I assigned by default. I assigned an empty string here. You may assign any default fallback value according to your need. This method helps reducing bugs &amp; errors if you use it wisely. For more information, you can read the official docs of <a href="https://lodash.com/docs/4.17.15#get">Lodash</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5F0m0SVSAwWzrok8rIAW9Q.png" /></figure><p>Thanks for reading! Do give me some claps if you find this article helpful! Happy coding &amp; Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bd9108a8d7f" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/filter-architecture-in-your-front-end-project-6bd9108a8d7f">Filter Architecture In Your Front-end Project</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maintain a clean code based in React — Part 2]]></title>
            <link>https://medium.com/geekculture/maintain-a-clean-code-based-in-react-part-2-b13323bfbd94?source=rss-447e99c96081------2</link>
            <guid isPermaLink="false">https://medium.com/p/b13323bfbd94</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Ayako]]></dc:creator>
            <pubDate>Mon, 13 Sep 2021 05:31:04 GMT</pubDate>
            <atom:updated>2021-09-13T05:31:04.072Z</atom:updated>
            <content:encoded><![CDATA[<h3>Maintain a clean code based in React — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P8bZB-R7iJDzvZSRc1CGIw.jpeg" /></figure><h3>Preface</h3><p>I believe almost every developer has been in a situation whereby you received a project from the previous developer, and you get stuck in the next minute, because you don’t understand the codes they wrote.</p><p><em>Bad naming conventions, Messy code logics, redundant codes, no comments etc.</em></p><p>You will slowly get drown in these mess, then you will end up just scratch it and re-do the whole thing yourself.</p><p>In the previous article, we mentioned several ideas on how to improve &amp; maintain the quality of your code based. Now, we will continue dive in into this topic. Let’s see how we can continue leverage the standard of our code!</p><p>Click here to read: <a href="https://unicorn-sky.medium.com/maintain-a-clean-code-based-in-react-26681019448">Part 1</a></p><h3>1. Clear naming convention</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJLZTrnGuRhmd6pobMRwdA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@callmefred?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Call Me Fred</a> on <a href="https://unsplash.com/s/photos/standard?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>If you’re working in a team, it is very important to have a clear and specific naming convention in your functions &amp; variables, so that other developers will understand it at the first glance.</p><p>It will be great to set a standard language, like English, when creating names. Follows the standard language that has been set. Try to avoid your own native language (<em>that is not English</em>) or mother tongue, because you might collaborate with developers from different countries. Unless you can 100000% ensures that your project only hires local developers.</p><p>If possible, try to avoid short form because not everyone will understand it, including yourself after several months when you look back to the code.</p><p>Besides that, you can consider to use plural for array. Let’s say you have a list of movies, you can declare the array as movies instead of movieList . Doesn’t it has a better readability when you name it as movies?</p><p>While for boolean values, you can also consider <strong><em>judgement style naming</em></strong>. This means that the name itself is like a question and you can get a <strong><em>YES</em></strong> or <strong><em>NO</em></strong> answer based on the observation. For example, you have an email and you wish to know whether its format is valid or invalid. In this case, you can consider to declare the function or variable name like isValidEmail . Same goes to other conditions as well. If you need a variable to check the existing of an image, you can declare it as hasImage .</p><p>I understand think for a good naming burn out some of your brain juice. But still, try to keep all your naming convention <strong><em>short &amp; simple</em></strong>.</p><p>Below is a not-so-good example of some naming conventions:</p><pre>// Functions</pre><pre>const getTZ = () =&gt; {};  // What is &#39;TZ&#39;?<br>const getLocationList = () = return &#39;array&#39;; // Too long<br>const getInputValidation = input =&gt; return &#39;boolean&#39;; // Less specific</pre><pre>// Variables</pre><pre>const x = &#39;100ml&#39;;      // What is the usage of &#39;x&#39;?<br>const zaoCanDian = &#39;&#39;;  // What is &#39;zaoCanDian&#39;? <br>const cinemaLocationList = [];  // Can be shorten</pre><p>This is how we can improve them:</p><pre>// Functions</pre><pre>const getTimezone = () =&gt; {};<br>const getLocations = () = return &#39;array&#39;; <br>const isInputValidated = input =&gt; return &#39;boolean&#39;;</pre><pre>// Variables</pre><pre>const waterVolume = &#39;100ml&#39;;<br>const breakfastShop = &#39;&#39;;<br>const cinemaLocations = [];</pre><p>In summary, these are the points you should take note when creating names:</p><ul><li>Set a standard language.</li><li>Avoid short form.</li><li>Use plural for array.</li><li>Use judgement style naming.</li><li>Avoid using language that is not following the language standard.</li></ul><blockquote>Be Clear, Specific, Short &amp; Simple</blockquote><h3>2. Make use of Conditional Statement</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DgrXrx5SGCPkY3-s7v4xHQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jannerboy62?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Nick Fewings</a> on <a href="https://unsplash.com/s/photos/yes-or-no?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Instead of using the traditional if...else statement, why not considering the usage of conditional operators such as ? || &amp; ? It will save you from the nested if...else hell loop.</p><p>Furthermore, it also helps to reduce the usage of useEffect when you’re working on a conditional component. For example, you wanna display a component upon successful API request, instead of toggles the component with useState and controls the DOM updates using useEffect , you may try this method as below:</p><pre>{ <strong>isSuccess</strong> &amp;&amp; &lt;div&gt; Only display if successful &lt;/div&gt; }</pre><pre>{ <strong>isSuccess</strong> ? &lt;div&gt; Component A &lt;/div&gt; : &lt;div&gt; Component B &lt;/div&gt; }</pre><p>This format below explains how’s the condition works:</p><blockquote>const <strong>isSuccess</strong> = [condition] === ‘TRUE’ ? return true : return false;</blockquote><p>You can use this practice in many places, including your functions, parameter checks and so on. Now, let us have a quick look on how to create a JS function that checks for even number. The function should return true if the number is even.</p><p>Here’s a not-so-good example:</p><pre>const <strong>isEven</strong> = <em>number</em> =&gt; {<br>  let result = &#39;&#39;;</pre><pre>if(number % 2) {<br>    result = true;<br>  } else {<br>    result = false;<br>  }</pre><pre>return result;<br>}</pre><p>The enhance version:</p><pre>const <strong>isEven</strong> = <em>number</em> =&gt; number % 2 === 0;</pre><p>Just a line will do. Amazing, isn’t it?</p><p>However, there’s something to take note. If you’re using conditional operators to return <em>classnames</em>, make sure to return an empty string if the condition is invalid. Otherwise, you’ll get a <strong><em>false </em></strong>value<strong><em> </em></strong>in the classname, which you can see it when you inspect the element.</p><pre>// Not-so-good<br>const className = [condition] &amp;&amp; &#39;bg-blue&#39;;</pre><pre>&lt;div class=&quot;<strong><em>false</em></strong> container&quot;&gt;Your component&lt;/div&gt;</pre><pre>// Better<br>const className = [condition] ? &#39;bg-blue&#39; ? &#39;&#39;;</pre><pre>&lt;div class=&quot;container&quot;&gt;Your component&lt;/div&gt;</pre><p>There are many more for you to explore on the usage of conditional operators. Just google around if you keen to learn more!</p><h3>3. Declares the Magic Numbers</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S53IdO0IaMWDv3-M5hxSNQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@sigmund?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Sigmund</a> on <a href="https://unsplash.com/s/photos/numbers?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Well, what is “<strong><em>magic number</em></strong>”? The <strong>magic number</strong> is any random number that appears in the code without any specific declaration. It doesn’t have a clear meaning. Just take a look at the code below:</p><pre>if (responseCode === 00) {<br>  console.log(&#39;test&#39;);<br>}</pre><p>Could you tell what is happening here? What is “00”? Thus, it’ll be nice to declare the number for better maintainability and readability. Eg.</p><pre>const FAILED_RESPONSE = 00;</pre><pre>if (responseCode === FAILED_RESPONSE) {<br>  console.log(&#39;test&#39;);<br>}</pre><p>It looks much clearer and understandable now. Try to practice this behaviour, it really helps a lot during your development.</p><h3>4. Separates the Constants &amp; Dummy Datas</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6LKiwWPBnYOtWY1A7kRw_w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@ninjason">Jason Leung</a> on Unsplash</figcaption></figure><p>I call them as <strong>CDs</strong>, but this is not the typical meaning of <em>Compact Disk </em>or<em> Christian Dior </em>that we used to know. In face, they are:</p><blockquote>Constant variable &amp; Dummy data</blockquote><p>Global variables are certain variables that will commonly used in the project. Normally, I will split the global constant variables into an individual file, then places it under the constants folder. Eg. constants/global.js.</p><p>This same goes to the dummy data, such as <em>array</em>, <em>array of object</em> and <em>object</em> that are created for testing purposes. Firstly, I will create a temporary mock file, for example mock.js, under the constants folder, then separate the data and keep them here.</p><p>This is another practice to keep the code neat &amp; clean, because I just need to import it whenever I wanna use it.</p><h3>Conclusions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_co8oA7RbqJ60jrdbll4tg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@fossy?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Fab Lentz</a> on <a href="https://unsplash.com/s/photos/clear-name?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Every change takes time. It might be a little hustle at first, but it will never be late to start.</p><p>Thanks for reading! If you like my article, please give me some claps!</p><p>If you wish to translate my article to another language, you are welcomed to do it! Please credit me in your post, and drop me a message in the comment box!</p><p>All the best on your journey! Have a nice day, Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b13323bfbd94" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/maintain-a-clean-code-based-in-react-part-2-b13323bfbd94">Maintain a clean code based in React — Part 2</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maintain a clean code based in React — Part 1]]></title>
            <link>https://medium.com/geekculture/maintain-a-clean-code-based-in-react-part-1-989dcba6892b?source=rss-447e99c96081------2</link>
            <guid isPermaLink="false">https://medium.com/p/989dcba6892b</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ayako]]></dc:creator>
            <pubDate>Mon, 13 Sep 2021 04:33:23 GMT</pubDate>
            <atom:updated>2021-09-13T04:33:23.550Z</atom:updated>
            <content:encoded><![CDATA[<h3>Maintain a clean code based in React — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WhR0GNM_wrfEawQ4HfU2ZQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@clemhlrdt?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Clément Hélardot</a> on <a href="https://unsplash.com/s/photos/programming?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Preface</h3><p>Have you ever been in a situation whereby your code submission gets rejected or received negative feedbacks from your project lead? Instead of letting all these negative emotions get overwhelmed and demotivate you, let’s take a step out and create something better!</p><p>As an engineer, we’re not just writing code that only computer could understand. Instead, we’re writing “human-understandable” codes. Clean code practiced will help you to maintain and structure a better react project. I understand it will be challenging at first, but trust me, in the end you’re helping yourself to survive during the project development road.</p><p>Here are some suggestions and tips on improving and maintaining a react project. So let’s get fired up!</p><h3>1. The imports statements</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKw8i6xDo1AEkFy4kEyClg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@flowforfrank?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ferenc Almasi</a> on <a href="https://unsplash.com/s/photos/javascript?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>This shall be the first part to organize in your react code.</p><p>We can import the files and modules by using <strong><em>relative imports</em></strong> and <strong><em>absolute imports</em></strong>. In most cases, especially when you’re working with a large scale project, it’s highly recommended to setup and use <strong><em>absolute imports</em></strong> for better readability and refactoring. Say goodbye to the ../../../xxxx nested folder path hell.</p><p>In this case, I came out with a set of <em>“</em><strong><em>React Import Structure (RIS)</em></strong>” in order to organize the dependencies in a neater and maintainable way as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0c4db914f25734210d1757770bb8166/href">https://medium.com/media/d0c4db914f25734210d1757770bb8166/href</a></iframe><p>Below is a not-so-good example of a bunch of import statements because they are unorganized with poor readability.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2201be80f213403471d078c9c4fa1df3/href">https://medium.com/media/2201be80f213403471d078c9c4fa1df3/href</a></iframe><p>Now you can see the differences after reorganizing the import statements by following the structure mentioned above. It’s a lot cleaner now, isn’t it?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94d3473280f56ad4edc4c3317601e733/href">https://medium.com/media/94d3473280f56ad4edc4c3317601e733/href</a></iframe><h3>2. Separation of the Styles</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pRj95hfmkIDo0AtgHtWIFg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@der_maik_?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Maik Jonietz</a> on <a href="https://unsplash.com/s/photos/css?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The more UI components you create, the more lengthy stylesheet you will get. Try to avoid inline styling because it has limitations when comes to CSS features supporting. It’s not really a good practice to have the styling and component codes together in the same file, because it will make things messier and less maintainable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0135e7f211e06874f36332b1198c8e8/href">https://medium.com/media/b0135e7f211e06874f36332b1198c8e8/href</a></iframe><p>Therefore, it’s better to separate the styling codes into another file, then import it only when necessary, which is also a way to help reducing the file size. Below is the sample of splitting the styling codes into different files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NgR9FnJBIRUKcCZrLCl9LA.png" /><figcaption>Sample of stylesheet splitting || <a href="https://marketplace.visualstudio.com/items?itemName=ayakoSky.sodagreen-theme">VSCode Theme Name: Sodagreen Theme</a></figcaption></figure><h3>3. Separation &amp; Reuse of the Functions</h3><p>This is same like the concept above. Having too many functions within a component file is a disaster too. Imagine you’re creating a large component, you add spice, sugar and everything “nice” in, sooner you file will easily grow more than 1,000+ lines of codes, but ends up the Powerpuff girls might not come out or it comes out with a less satisfied performance result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*5P8_2YzxlWXuyEaEkaNRUA.gif" /><figcaption>Professor Utonium</figcaption></figure><p>Thus, splitting out the business logics and functions is a better choice because it can be reused globally in the project. In another way, it does provide a cleaner and maintainable code based. Usually, I will keep those separated logics into an utils folder under the src directory for better management. This is my approach, you may consider your own way to organize it.</p><h3>4. Remove the unused 3C’s</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Xt7ScxuuxESDPjE5v_6JlQ.jpeg" /></figure><p>You must be wondering what are the <strong>3Cs </strong>here.</p><p>It’s not the typical<em> Car, Cash, Credit Card</em></p><p>Instead they are:</p><blockquote>Consoles, Comments, Codes</blockquote><p>Removes the unnecessary and redundancy codes will significantly improve the code quality and also slim down the bundle size. Adding comments is an awesome habit, but only add it when necessary.</p><p>Moreover, You may integrate ESLint and Prettier to help keep track and utilize the coding standard in your project. From here, you can notice if there’s any unused libraries. If you’re pretty sure you will not be using those dependencies sooner or later, and it will not impact your project, advices is to offload them to reduce the project size.</p><p><em>Read here for the </em><a href="https://unicorn-sky.medium.com/configures-eslint-prettier-in-react-hooks-project-81db775a6db0"><em>Configuration of ESLint and prettier in React project</em></a><em>.</em></p><h3>5. Standard naming conventions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJLZTrnGuRhmd6pobMRwdA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@callmefred?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Call Me Fred</a> on <a href="https://unsplash.com/s/photos/standard?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>When comes to coding, there are different types of naming conventions such as <strong>PascalCase, camelCase, kebab-case, snack_case</strong> etc.</p><p>Ideally, it’s to set a primary naming convention in order to achieve a neat and readable code based on you project. For example, you may choose <strong>camelCase</strong> for your business logics and functions, <strong>PascalCase</strong> for your component name and an uppercase <strong>SNACK_CASE</strong> for your global variables.</p><pre>// PascalCase<br>const NewComponent = () =&gt; (&lt;div&gt;Loading...&lt;/div&gt;);</pre><pre>// camelCase<br>const getResponses = () =&gt; console.log(responses);</pre><pre>// SNACK_CASE<br>const PRIMARY_COLOR = &#39;blue&#39;;</pre><h3>Conclusions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ipY1hFf1aPrBK2f06V9Sw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@srosinger3997?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Samantha Gades</a> on <a href="https://unsplash.com/s/photos/clean?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The code restructuring progress is kinda painful at first, but better worse now than worse later. When time passes, you will definitely becomes more beneficial from it:</p><ul><li>Well-organized code with good readability and maintainability.</li><li>Improves your app’s performance in another way.</li><li>Loves and respect from your teammates and other future-joining developers.</li><li><em>Discover more yourself</em>…. ☺</li></ul><p>Thanks for reading, cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=989dcba6892b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/maintain-a-clean-code-based-in-react-part-1-989dcba6892b">Maintain a clean code based in React — Part 1</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Tips for a Clean CodeBase in React]]></title>
            <link>https://ayako-dev.medium.com/5-tips-for-a-clean-codebase-in-react-aec2c4a0028c?source=rss-447e99c96081------2</link>
            <guid isPermaLink="false">https://medium.com/p/aec2c4a0028c</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[tips]]></category>
            <dc:creator><![CDATA[Ayako]]></dc:creator>
            <pubDate>Sat, 11 Sep 2021 11:08:41 GMT</pubDate>
            <atom:updated>2021-09-11T11:08:41.485Z</atom:updated>
            <content:encoded><![CDATA[<h4>React Clean Code Tips: Part 01</h4><h4>5 Clean Code Tips Every Developer Should Aware of</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KbZ682_lGkD7EXkStWFtmA.jpeg" /></figure><h3>Preface</h3><p>Have you ever been in a situation whereby your code submission gets rejected or received negative feedback from your project lead? Instead of letting all these negative emotions get overwhelmed and demotivate you, let’s take a step out and create something better!</p><p>As an engineer, we’re not just writing code that the only computer could understand. Instead, we’re writing “human-understandable” codes. Clean code practiced will help you to maintain and structure a better react project. I understand it will be challenging at first, but trust me, in the end, you’re helping yourself to survive during the project development road.</p><p>Here are some suggestions and tips on improving and maintaining a react project. So let’s get fired up!</p><h3>1. The imports statements</h3><p>This shall be the first part to organize in your react code.</p><p>We can import the files and modules by using <strong><em>relative imports</em></strong> and <strong><em>absolute imports</em></strong>. In most cases, especially when working with a large-scale project, it’s highly recommended to set up and use <strong><em>absolute imports</em></strong> for better readability and refactoring. Say goodbye to the ../../../xxxx nested folder path hell.</p><p>In this case, I came out with a set of <em>“</em><strong><em>React Import Structure (RIS)</em></strong>” to organize the dependencies in a neater and maintainable way as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0c4db914f25734210d1757770bb8166/href">https://medium.com/media/d0c4db914f25734210d1757770bb8166/href</a></iframe><p>Below is a not-so-good example of a bunch of import statements because they are unorganized with poor readability.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2201be80f213403471d078c9c4fa1df3/href">https://medium.com/media/2201be80f213403471d078c9c4fa1df3/href</a></iframe><p>Now you can see the differences after reorganizing the import statements by following the structure mentioned above. Of course, it’s a lot cleaner now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94d3473280f56ad4edc4c3317601e733/href">https://medium.com/media/94d3473280f56ad4edc4c3317601e733/href</a></iframe><h3>2. Separation of the Styles</h3><p>The more UI components you create, the more lengthy stylesheet you will get. Try to avoid inline styling because it has limitations when comes to CSS features supporting. Also, it’s not really good to have the styling and component codes together in the same file because it will make things messier and less maintainable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0135e7f211e06874f36332b1198c8e8/href">https://medium.com/media/b0135e7f211e06874f36332b1198c8e8/href</a></iframe><p>Therefore, it’s better to separate the styling codes into another file, then import it only when necessary, which is also a way to help to reduce the file size. Below is the sample of splitting the styling codes into different files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NgR9FnJBIRUKcCZrLCl9LA.png" /><figcaption>Sample of stylesheet splitting || <a href="https://marketplace.visualstudio.com/items?itemName=ayakoSky.sodagreen-theme">VSCode Theme Name: Sodagreen Theme</a></figcaption></figure><h3>3. Separation &amp; Reuse of the Functions</h3><p>This is the same as the concept above. Having too many functions within a component file is a disaster too. Imagine you’re creating a large component, you add spice, sugar, and everything “nice” in, sooner your file will easily grow more than 1,000+ lines of codes, but ends up the Powerpuff girls might not come out or it comes out with a less satisfying performance result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*5P8_2YzxlWXuyEaEkaNRUA.gif" /><figcaption>Professor Utonium</figcaption></figure><p>Thus, splitting out the business logic and functions is a better choice because it can be reused globally in the project. In another way, it does provide a cleaner and maintainable code-based. Usually, I will keep those separated logics into an utils folder under the src directory for better management. This is my approach. You may consider your own way to organize it.</p><h3>4. Remove the unused 3C’s</h3><p>You must be wondering what are the <strong>3Cs </strong>here.</p><p>It’s not the typical<em> Car, Cash, Credit Card.</em></p><p>Instead, they are:</p><blockquote>Consoles, Comments, Codes</blockquote><p>Removing unnecessary and redundancy codes will significantly improve code quality and slim down the bundle size. Adding comments is an awesome habit, but only add it when necessary.</p><p>Moreover, You may integrate ESLint and Prettier to help keep track and utilize the coding standard in your project. From here, you can notice if there are any unused libraries. If you’re pretty sure you will not be using those dependencies sooner or later, and it will not impact your project, advice is to offload them to reduce the project size.</p><p><em>Read here for the </em><a href="https://unicorn-sky.medium.com/configures-eslint-prettier-in-react-hooks-project-81db775a6db0"><em>Configuration of ESLint and prettier in React project</em></a><em>.</em></p><h3>5. Standard naming conventions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJLZTrnGuRhmd6pobMRwdA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@callmefred?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Call Me Fred</a> on <a href="https://unsplash.com/s/photos/standard?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>There are different naming conventions such as <strong>PascalCase, camelCase, kebab-case, snack_case,</strong> etc.</p><p>Ideally, it’s to set a primary naming convention to achieve a neat and readable code based on your project. For example, you may choose <strong>camelCase</strong> for your business logic and functions, <strong>PascalCase</strong> for your component name, and an uppercase <strong>SNACK_CASE</strong> for your global variables.</p><pre>// PascalCase<br>const NewComponent = () =&gt; (&lt;div&gt;Loading...&lt;/div&gt;);</pre><pre>// camelCase<br>const getResponses = () =&gt; console.log(responses);</pre><pre>// SNACK_CASE<br>const PRIMARY_COLOR = &#39;blue&#39;;</pre><h3>Conclusions</h3><p>The code restructuring progress is quite painful at first, but better worse now than worse later. When time passes, you will definitely become more beneficial from it:</p><ul><li>Well-organized code with good readability and maintainability.</li><li>Improves your app’s performance in another way.</li><li>Loves and respect from your teammates and other future-joining developers.</li><li><em>Discover more yourself</em>…. ☺</li></ul><p>Thanks for reading, cheers!</p><h3>Learn More</h3><ul><li><a href="https://enlear.academy/usememo-react-hook-a88f2e236eff">How to Use useMemo Hook in React</a></li><li><a href="https://enlear.academy/the-useref-hook-practical-explanation-ef333180dcbb">How to Use useRef Hook in React</a></li><li><a href="https://enlear.academy/7-reasons-why-should-start-using-react-8fc432b79fc1">7 Reasons Why You Should Start Using React</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aec2c4a0028c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Tips for a Clean CodeBase in React]]></title>
            <link>https://ayako-dev.medium.com/maintain-a-clean-code-based-in-react-part-2-6a1195a6bee2?source=rss-447e99c96081------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a1195a6bee2</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Ayako]]></dc:creator>
            <pubDate>Sat, 11 Sep 2021 09:11:35 GMT</pubDate>
            <atom:updated>2021-09-11T15:19:44.865Z</atom:updated>
            <content:encoded><![CDATA[<h4>REACT CLEAN CODE TIPS: PART 02</h4><h4>5 Clean Code Tips Every Developer Should Aware of</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iFb5En8UTMF1zmDyeM9NUg.jpeg" /></figure><h3>Preface</h3><p>I believe almost every developer has been in a situation whereby you received a project from the previous developer. Then, you get stuck in the next minute because you don’t understand the codes they wrote.</p><p><em>Lousy naming conventions, Messy code logic, redundant codes, no comments, etc.</em></p><p>You will slowly get drown in this mess. Then you will end up just scratch it and re-do the whole thing yourself.</p><p>In the previous article, we mentioned several ideas on how to improve &amp; maintain the quality of your code based. Now, we will continue to dive into this topic. Let’s see how we can continue to leverage the standard of our code!</p><p>Click here to read: <a href="https://unicorn-sky.medium.com/maintain-a-clean-code-based-in-react-26681019448">Part 1</a></p><h3>1. Clear naming convention</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJLZTrnGuRhmd6pobMRwdA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@callmefred?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Call Me Fred</a> on <a href="https://unsplash.com/s/photos/standard?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>If you’re working in a team, it is essential to have a clear and specific naming convention in your functions &amp; variables so that other developers will understand it at first glance.</p><p>It will be great to set a standard language, like English, when creating names. Follows the standard language that has been established. Try to avoid your native language (<em>not English</em>) or mother tongue because you might collaborate with developers from different countries. Unless you can 100000% ensures that your project only hires local developers.</p><p>If possible, try to avoid short form because not everyone will understand it, including yourself, after several months when you look back to the code.</p><p>Besides that, you can consider using plural for the array. For example, let’s say you have a list of movies. You can declare the array as movies instead of a movie list. Doesn’t it have better readability when you name it as movies?</p><p>While for boolean values, you can also consider <strong><em>judgment style naming</em></strong>. This means that the name itself is like a question, and you can get a <strong><em>YES</em></strong> or <strong><em>NO</em></strong> answer based on the observation. For example, you have an email, and you wish to know whether its format is valid or invalid. In this case, you can consider declaring the function or variable name like isValidEmail. The same goes for other conditions as well. For example, if you need a variable to check the existence of an image, you can declare it as hasImage.</p><p>Think on an excellent naming, burn out some of your brain juice. But still, try to keep all your naming conventions <strong><em>short &amp; simple</em></strong>.</p><p>Below is a not-so-good example of some naming conventions:</p><pre>// Functions</pre><pre>const getTZ = () =&gt; {};  // What is &#39;TZ&#39;?<br>const getLocationList = () = return &#39;array&#39;; // Too long<br>const getInputValidation = input =&gt; return &#39;boolean&#39;; // Less specific</pre><pre>// Variables</pre><pre>const x = &#39;100ml&#39;;      // What is the usage of &#39;x&#39;?<br>const zaoCanDian = &#39;&#39;;  // What is &#39;zaoCanDian&#39;? <br>const cinemaLocationList = [];  // Can be shorten</pre><p>This is how we can improve them:</p><pre>// Functions</pre><pre>const getTimezone = () =&gt; {};<br>const getLocations = () = return &#39;array&#39;; <br>const isInputValidated = input =&gt; return &#39;boolean&#39;;</pre><pre>// Variables</pre><pre>const waterVolume = &#39;100ml&#39;;<br>const breakfastShop = &#39;&#39;;<br>const cinemaLocations = [];</pre><p>In summary, these are the points you should take note of when creating names:</p><ul><li>Set a standard language.</li><li>Avoid short form.</li><li>Use plural for the array.</li><li>Use judgment style naming.</li><li>Avoid using language that is not following the language standard.</li></ul><blockquote>Be Clear, Specific, Short &amp; Simple</blockquote><h3>2. Make use of Conditional Statement</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DgrXrx5SGCPkY3-s7v4xHQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jannerboy62?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Nick Fewings</a> on <a href="https://unsplash.com/s/photos/yes-or-no?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Instead of using the traditional if...else statement, why not considering the usage of conditional operators such as ? || &amp; ? It will save you from the nested if...else hell loop.</p><p>Furthermore, it also helps to reduce the usage useEffect when you’re working on a conditional component. For example, you wanna display a component upon successful API request, instead of toggles the component with useState and controls the DOM updates using useEffect , you may try this method as below:</p><pre>{ <strong>isSuccess</strong> &amp;&amp; &lt;div&gt; Only display if successful &lt;/div&gt; }</pre><pre>{ <strong>isSuccess</strong> ? &lt;div&gt; Component A &lt;/div&gt; : &lt;div&gt; Component B &lt;/div&gt; }</pre><p>This format below explains how’s the condition works:</p><blockquote>const <strong>isSuccess</strong> = [condition] === ‘TRUE’ ? return true : return false;</blockquote><p>You can use this practice in many places, including your functions, parameter checks, and so on. Now, let us have a quick look at how to create a JS function that checks for even numbers. The function should return true if the number is even.</p><p>Here’s a not-so-good example:</p><pre>const <strong>isEven</strong> = <em>number</em> =&gt; {<br>  let result = &#39;&#39;;</pre><pre>if(number % 2) {<br>    result = true;<br>  } else {<br>    result = false;<br>  }</pre><pre>return result;<br>}</pre><p>The enhance version:</p><pre>const <strong>isEven</strong> = <em>number</em> =&gt; number % 2 === 0;</pre><p>Just a line will do. Amazing, isn’t it?</p><p>However, there’s something to take note of. If you’re using conditional operators to return <em>classnames</em>, make sure to return an empty string if the condition is invalid. Otherwise, you’ll get a <strong><em>false </em></strong>value<strong><em> </em></strong>in the classname, which you can see when you inspect the element.</p><pre>// Not-so-good<br>const className = [condition] &amp;&amp; &#39;bg-blue&#39;;</pre><pre>&lt;div class=&quot;<strong><em>false</em></strong> container&quot;&gt;Your component&lt;/div&gt;</pre><pre>// Better<br>const className = [condition] ? &#39;bg-blue&#39; ? &#39;&#39;;</pre><pre>&lt;div class=&quot;container&quot;&gt;Your component&lt;/div&gt;</pre><p>There are many more for you to explore on the usage of conditional operators. Just google around if you keen to learn more!</p><h3>3. Declares the Magic Numbers</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S53IdO0IaMWDv3-M5hxSNQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@sigmund?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Sigmund</a> on <a href="https://unsplash.com/s/photos/numbers?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Well, what is “<strong><em>magic number</em></strong>”? The <strong>magic number</strong> is any random number that appears in the code without any specific declaration. It doesn’t have a clear meaning. Just take a look at the code below:</p><pre>if (responseCode === 00) {<br>  console.log(&#39;test&#39;);<br>}</pre><p>Could you tell me what is happening here? What is “00”? Thus, it’ll be nice to declare the number for better maintainability and readability. Eg.</p><pre>const FAILED_RESPONSE = 00;</pre><pre>if (responseCode === FAILED_RESPONSE) {<br>  console.log(&#39;test&#39;);<br>}</pre><p>It looks much clearer and understandable now. Try to practice this behavior, it really helps a lot during your development.</p><h3>4. Separates the Constants &amp; Dummy Data</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6LKiwWPBnYOtWY1A7kRw_w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@ninjason">Jason Leung</a> on Unsplash</figcaption></figure><p>I call them as <strong>CDs</strong>, but this is not the typical meaning of <em>Compact Disk </em>or<em> Christian Dior </em>that we used to know. In face, they are:</p><blockquote>Constant variable &amp; Dummy data</blockquote><p>Global variables are certain variables that will be commonly used in the project. Normally, I will split the global constant variables into an individual file, then places it under the constants folder. Eg. constants/global.js.</p><p>This same goes to the dummy data, such as an <em>array</em>, an <em>array of object,</em> and <em>objects</em> that are created for testing purposes. Firstly, I will create a temporary mock file, for example mock.js, under the constants folder, then separate the data and keep them here.</p><p>This is another practice to keep the code neat &amp; clean because I just need to import it whenever I wanna use it.</p><h3>Conclusions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_co8oA7RbqJ60jrdbll4tg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@fossy?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Fab Lentz</a> on <a href="https://unsplash.com/s/photos/clear-name?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Every change takes time. It might be a little hustle at first, but it will never be late to start.</p><p>Thanks for reading! If you like my article, please give me some claps!</p><p>If you wish to translate my article to another language, you are welcomed to do it! Please credit me in your post, and drop me a message in the comment box!</p><p>All the best on your journey! Have a nice day, Cheers!</p><h3>Learn More</h3><p><a href="https://enlear.academy/5-tips-for-a-clean-codebase-in-react-aec2c4a0028c">https://enlear.academy/5-tips-for-a-clean-codebase-in-react-aec2c4a0028c</a></p><p><a href="https://enlear.academy/top-3-javascript-framework-for-server-side-rendering-276c4848fbbe?source=collection_detail----ed5bbce3edf9-----122-----------------------">https://enlear.academy/top-3-javascript-framework-for-server-side-rendering-276c4848fbbe?source=collection_detail----ed5bbce3edf9-----122-----------------------</a></p><p><a href="https://enlear.academy/all-about-high-order-component-and-render-props-patterns-60bc2492548b?source=collection_detail----ed5bbce3edf9-----73-----------------------">https://enlear.academy/all-about-high-order-component-and-render-props-patterns-60bc2492548b?source=collection_detail----ed5bbce3edf9-----73-----------------------</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a1195a6bee2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maintain a clean code based in React — Part 2]]></title>
            <link>https://itnext.io/maintain-a-clean-code-based-in-react-part-2-c609ae9b559e?source=rss-447e99c96081------2</link>
            <guid isPermaLink="false">https://medium.com/p/c609ae9b559e</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Ayako]]></dc:creator>
            <pubDate>Tue, 31 Aug 2021 14:13:09 GMT</pubDate>
            <atom:updated>2021-09-06T13:50:32.585Z</atom:updated>
            <content:encoded><![CDATA[<h3>Maintain a clean code based in React — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P8bZB-R7iJDzvZSRc1CGIw.jpeg" /></figure><h3><strong>Preface</strong></h3><p>I believe almost every developer has been in a situation whereby you received a project from the previous developer, and you get stuck in the next minute, because you don’t understand the codes they wrote.</p><p><em>Bad naming conventions, Messy code logics, redundant codes, no comments etc.</em></p><p>You will slowly get drown in these mess, then you will end up just scratch it and re-do the whole thing yourself.</p><p>In the previous article, we mentioned several ideas on how to improve &amp; maintain the quality of your code based. Now, we will continue dive in into this topic. Now, let’s see how we can continue leverage the standard of our code!</p><p>Click here to read: <a href="https://unicorn-sky.medium.com/maintain-a-clean-code-based-in-react-26681019448">Part 1</a></p><h3>1. Clear naming convention</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJLZTrnGuRhmd6pobMRwdA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@callmefred?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Call Me Fred</a> on <a href="https://unsplash.com/s/photos/standard?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>If you’re working in a team, it is very important to have a clear and specific naming convention in your functions &amp; variables, so that other developers will understand it at the first glance.</p><p>It will be great to set a standard language, like English, when creating names. Follows the standard language that has been set. Try to avoid your own native language (<em>that is not English</em>) or mother tongue, because you might collaborate with developers from different countries. Unless you can 100000% ensures that your project only hires local developers.</p><p>If possible, try to avoid short form because not everyone will understand it, including yourself after several months when you look back to the code.</p><p>Besides that, you can consider to use plural for array. Let’s say you have a list of movies, you can declare the array as movies instead of movieList . Doesn’t it has a better readability when you name it as movies?</p><p>While for boolean values, you can also consider <strong><em>judgement style naming</em></strong>. This means that the name itself is like a question and you can get a <strong><em>YES</em></strong> or <strong><em>NO</em></strong> answer based on the observation. For example, you have an email and you wish to know whether its format is valid or invalid. In this case, you can consider to declare the function or variable name like isValidEmail . Same goes to other conditions as well. If you need a variable to check the existing of an image, you can declare it as hasImage .</p><p>I understand think for a good naming burn out some of your brain juice. But still, try to keep all your naming convention <strong><em>short &amp; simple</em></strong>.</p><p>Below is a not-so-good example of some naming conventions:</p><pre>// Functions</pre><pre>const getTZ = () =&gt; {};  // What is &#39;TZ&#39;?<br>const getLocationList = () = return &#39;array&#39;; // Too long<br>const getInputValidation = input =&gt; return &#39;boolean&#39;; // Less specific</pre><pre>// Variables</pre><pre>const x = &#39;100ml&#39;;      // What is the usage of &#39;x&#39;?<br>const zaoCanDian = &#39;&#39;;  // What is &#39;zaoCanDian&#39;? <br>const cinemaLocationList = [];  // Can be shorten</pre><p>This is how we can improve them:</p><pre>// Functions</pre><pre>const getTimezone = () =&gt; {};<br>const getLocations = () = return &#39;array&#39;; <br>const isInputValidated = input =&gt; return &#39;boolean&#39;;</pre><pre>// Variables</pre><pre>const waterVolume = &#39;100ml&#39;;<br>const breakfastShop = &#39;&#39;;<br>const cinemaLocations = [];</pre><p>In summary, these are the points you should take note when creating names:</p><ul><li>Set a standard language.</li><li>Avoid short form.</li><li>Use plural for array.</li><li>Use judgement style naming.</li><li>Avoid using language that is not following the language standard.</li></ul><blockquote><em>Be Clear, Specific, Short &amp; Simple</em></blockquote><h3>2. Make use of Conditional Statement</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DgrXrx5SGCPkY3-s7v4xHQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jannerboy62?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Nick Fewings</a> on <a href="https://unsplash.com/s/photos/yes-or-no?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Instead of using the traditional if...else statement, why not considering the usage of conditional operators such as ? || &amp; ? It will save you from the nested if...else hell loop.</p><p>Furthermore, it also helps to reduce the usage of useEffect when you’re working on a conditional component. For example, you wanna display a component upon successful API request, instead of toggles the component with useState and controls the DOM updates using useEffect , you may try this method as below:</p><pre>{ <strong>isSuccess</strong> &amp;&amp; &lt;div&gt; Only display if successful &lt;/div&gt; }</pre><pre>{ <strong>isSuccess</strong> ? &lt;div&gt; Component A &lt;/div&gt; : &lt;div&gt; Component B &lt;/div&gt; }</pre><p>This format below explains how’s the condition works:</p><blockquote>const <strong>isSuccess</strong> = [condition] === ‘TRUE’ ? return true : return false;</blockquote><p>You can use this practice in many places, including your functions, parameter checks and so on. Now, let us have a quick look on how to create a JS function that checks for even number. The function should return true if the number is even.</p><p>Here’s a not-so-good example:</p><pre>const <strong>isEven</strong> = <em>number</em> =&gt; {<br>  let result = &#39;&#39;;</pre><pre>  if(number % 2) {<br>    result = true;<br>  } else {<br>    result = false;<br>  }</pre><pre>  return result;<br>}</pre><p>The enhance version:</p><pre>const <strong>isEven</strong> = <em>number</em> =&gt; number % 2 === 0; </pre><p>Just a line will do. Amazing, isn’t it?</p><p>However, there’s something to take note. If you’re using conditional operators to return <em>classnames</em>, make sure to return an empty string if the condition is invalid. Otherwise, you’ll get a <strong><em>false </em></strong>value<strong><em> </em></strong>in the classname, which you can see it when you inspect the element.</p><pre>// Not-so-good<br>const className = [condition] &amp;&amp; &#39;bg-blue&#39;; </pre><pre>&lt;div class=&quot;<strong><em>false</em></strong> container&quot;&gt;Your component&lt;/div&gt;</pre><pre>// Better<br>const className = [condition] ? &#39;bg-blue&#39; ? &#39;&#39;;</pre><pre>&lt;div class=&quot;container&quot;&gt;Your component&lt;/div&gt;</pre><p>There are many more for you to explore on the usage of conditional operators. Just google around if you keen to learn more!</p><h3><strong>3. Declares the Magic Numbers</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S53IdO0IaMWDv3-M5hxSNQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@sigmund?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Sigmund</a> on <a href="https://unsplash.com/s/photos/numbers?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Well, what is “<strong><em>magic number</em></strong>”? The <strong>magic number</strong> is any random number that appears in the code without any specific declaration. It doesn’t have a clear meaning. Just take a look at the code below:</p><pre>if (responseCode === 00) {<br>  console.log(&#39;test&#39;);<br>}</pre><p>Could you tell what is happening here? What is “00”? Thus, it’ll be nice to declare the number for better maintainability and readability. Eg.</p><pre>const FAILED_RESPONSE = 00;</pre><pre>if (responseCode === FAILED_RESPONSE) {<br>  console.log(&#39;test&#39;);<br>}</pre><p>It looks much clearer and understandable now. Try to practice this behaviour, it really helps a lot during your development.</p><h3>4. Separates the Constants &amp; Dummy Datas</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6LKiwWPBnYOtWY1A7kRw_w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@ninjason">Jason Leung</a> on Unsplash</figcaption></figure><p>I call them as <strong>CDs</strong>, but this is not the typical meaning of <em>Compact Disk </em>or<em> Christian Dior </em>that we used to know. In face, they are:</p><blockquote>Constant variable &amp; Dummy data</blockquote><p>Global variables are certain variables that will commonly used in the project. Normally, I will split the global constant variables into an individual file, then places it under the constants folder. Eg. constants/global.js.</p><p>This same goes to the dummy data, such as <em>array</em>, <em>array of object</em> and <em>object</em> that are created for testing purposes. Firstly, I will create a temporary mock file, for example mock.js, under the constants folder, then separate the data and keep them here.</p><p>This is another practice to keep the code neat &amp; clean, because I just need to import it whenever I wanna use it.</p><h3>Conclusions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_co8oA7RbqJ60jrdbll4tg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@fossy?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Fab Lentz</a> on <a href="https://unsplash.com/s/photos/clear-name?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Every change takes time. It might be a little hustle at first, but it will never be late to start.</p><p>Thanks for reading! If you like my article, please give me some claps!</p><p>If you wish to translate my article to another language, you are welcomed to do it! Please credit me in your post, and drop me a message in the comment box!</p><p>All the best on your journey! Have a nice day, Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c609ae9b559e" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/maintain-a-clean-code-based-in-react-part-2-c609ae9b559e">Maintain a clean code based in React — Part 2</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maintain a clean code based in React — Part 1]]></title>
            <link>https://itnext.io/maintain-a-clean-code-based-in-react-26681019448?source=rss-447e99c96081------2</link>
            <guid isPermaLink="false">https://medium.com/p/26681019448</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding-style]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Ayako]]></dc:creator>
            <pubDate>Thu, 08 Jul 2021 14:31:47 GMT</pubDate>
            <atom:updated>2021-09-06T13:49:11.199Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WhR0GNM_wrfEawQ4HfU2ZQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@clemhlrdt?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Clément Hélardot</a> on <a href="https://unsplash.com/s/photos/programming?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3><strong>Preface</strong></h3><p>Have you ever been in a situation whereby your code submission gets rejected or received negative feedbacks from your project lead? Instead of letting all these negative emotions get overwhelmed and demotivate you, let’s take a step out and create something better!</p><p>As an engineer, we’re not just writing code that only computer could understand. Instead, we’re writing “human-understandable” codes. Clean code practiced will help you to maintain and structure a better react project. I understand it will be challenging at first, but trust me, in the end you’re helping yourself to survive during the project development road.</p><p>Here are some suggestions and tips on improving and maintaining a react project. So let’s get fired up!</p><h3><strong>1. The imports statements</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKw8i6xDo1AEkFy4kEyClg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@flowforfrank?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ferenc Almasi</a> on <a href="https://unsplash.com/s/photos/javascript?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>This shall be the first part to organize in your react code.</p><p>We can import the files and modules by using <strong><em>relative imports</em></strong> and <strong><em>absolute imports</em></strong>. In most cases, especially when you’re working with a large scale project, it’s highly recommended to setup and use <strong><em>absolute imports</em></strong> for better readability and refactoring. Say goodbye to the ../../../xxxx nested folder path hell.</p><p>In this case, I came out with a set of <em>“</em><strong><em>React Import Structure (RIS)</em></strong>” in order to organize the dependencies in a neater and maintainable way as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0c4db914f25734210d1757770bb8166/href">https://medium.com/media/d0c4db914f25734210d1757770bb8166/href</a></iframe><p>Below is a not-so-good example of a bunch of import statements because they are unorganized with poor readability.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2201be80f213403471d078c9c4fa1df3/href">https://medium.com/media/2201be80f213403471d078c9c4fa1df3/href</a></iframe><p>Now you can see the differences after reorganizing the import statements by following the structure mentioned above. It’s a lot cleaner now, isn’t it?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94d3473280f56ad4edc4c3317601e733/href">https://medium.com/media/94d3473280f56ad4edc4c3317601e733/href</a></iframe><h3><strong>2. Separation of the Styles</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pRj95hfmkIDo0AtgHtWIFg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@der_maik_?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Maik Jonietz</a> on <a href="https://unsplash.com/s/photos/css?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The more UI components you create, the more lengthy stylesheet you will get. Try to avoid inline styling because it has limitations when comes to CSS features supporting. It’s not really a good practice to have the styling and component codes together in the same file, because it will make things messier and less maintainable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0135e7f211e06874f36332b1198c8e8/href">https://medium.com/media/b0135e7f211e06874f36332b1198c8e8/href</a></iframe><p>Therefore, it’s better to separate the styling codes into another file, then import it only when necessary, which is also a way to help reducing the file size. Below is the sample of splitting the styling codes into different files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NgR9FnJBIRUKcCZrLCl9LA.png" /><figcaption>Sample of stylesheet splitting || <a href="https://marketplace.visualstudio.com/items?itemName=ayakoSky.sodagreen-theme">VSCode Theme Name: Sodagreen Theme</a></figcaption></figure><h3>3. Separation &amp; Reuse of the Functions</h3><p>This is same like the concept above. Having too many functions within a component file is a disaster too. Imagine you’re creating a large component, you add spice, sugar and everything “nice” in, sooner you file will easily grow more than 1,000+ lines of codes, but ends up the Powerpuff girls might not come out or it comes out with a less satisfied performance result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*5P8_2YzxlWXuyEaEkaNRUA.gif" /><figcaption>Professor Utonium</figcaption></figure><p>Thus, splitting out the business logics and functions is a better choice because it can be reused globally in the project. In another way, it does provide a cleaner and maintainable code based. Usually, I will keep those separated logics into an utils folder under the src directory for better management. This is my approach, you may consider your own way to organize it.</p><h3>4. Remove the unused 3C’s</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Xt7ScxuuxESDPjE5v_6JlQ.jpeg" /></figure><p>You must be wondering what are the <strong>3Cs </strong>here.</p><p>It’s not the typical<em> Car, Cash, Credit Card</em></p><p>Instead they are:</p><blockquote>Consoles, Comments, Codes</blockquote><p>Removes the unnecessary and redundancy codes will significantly improve the code quality and also slim down the bundle size. Adding comments is an awesome habit, but only add it when necessary.</p><p>Moreover, You may integrate ESLint and Prettier to help keep track and utilize the coding standard in your project. From here, you can notice if there’s any unused libraries. If you’re pretty sure you will not be using those dependencies sooner or later, and it will not impact your project, advices is to offload them to reduce the project size.</p><p><em>Read here for the </em><a href="https://unicorn-sky.medium.com/configures-eslint-prettier-in-react-hooks-project-81db775a6db0"><em>Configuration of ESLint and prettier in React project</em></a><em>.</em></p><h3>5. Standard naming conventions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJLZTrnGuRhmd6pobMRwdA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@callmefred?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Call Me Fred</a> on <a href="https://unsplash.com/s/photos/standard?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>When comes to coding, there are different types of naming conventions such as <strong>PascalCase, camelCase, kebab-case, snack_case</strong> etc.</p><p>Ideally, it’s to set a primary naming convention in order to achieve a neat and readable code based on you project. For example, you may choose <strong>camelCase</strong> for your business logics and functions, <strong>PascalCase</strong> for your component name and an uppercase <strong>SNACK_CASE</strong> for your global variables.</p><pre>// PascalCase<br>const NewComponent = () =&gt; (&lt;div&gt;Loading...&lt;/div&gt;);</pre><pre>// camelCase<br>const getResponses = () =&gt; console.log(responses);</pre><pre>// SNACK_CASE<br>const PRIMARY_COLOR = &#39;blue&#39;;</pre><h3>Conclusions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ipY1hFf1aPrBK2f06V9Sw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@srosinger3997?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Samantha Gades</a> on <a href="https://unsplash.com/s/photos/clean?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The code restructuring progress is kinda painful at first, but better worse now than worse later. When time passes, you will definitely becomes more beneficial from it:</p><ul><li>Well-organized code with good readability and maintainability.</li><li>Improves your app’s performance in another way.</li><li>Loves and respect from your teammates and other future-joining developers.</li><li><em>Discover more yourself</em>…. ☺</li></ul><p>Thanks for reading, cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26681019448" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/maintain-a-clean-code-based-in-react-26681019448">Maintain a clean code based in React — Part 1</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>