<?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[Hazesoft - Medium]]></title>
        <description><![CDATA[Official Blog - Medium]]></description>
        <link>https://medium.com/hazesoft?source=rss----ac2d2beea86e---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Hazesoft - Medium</title>
            <link>https://medium.com/hazesoft?source=rss----ac2d2beea86e---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:46:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/hazesoft" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Efficient Code Organization in React-Redux]]></title>
            <link>https://medium.com/hazesoft/efficient-code-organization-in-reactjs-416739947b50?source=rss----ac2d2beea86e---4</link>
            <guid isPermaLink="false">https://medium.com/p/416739947b50</guid>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Vivek Ghimire]]></dc:creator>
            <pubDate>Thu, 05 Apr 2018 10:19:29 GMT</pubDate>
            <atom:updated>2018-05-30T04:42:02.559Z</atom:updated>
            <content:encoded><![CDATA[<p>The more I code, the more I realize the significance of a proper organizational system in application development. Especially on a large-scale project, various code organization techniques and coding paradigms need to be developed beforehand to make sure that the the code remains clean and development doesn’t wind up sloppy somewhere along the way. This requires fundamentally re-thinking our existing coding conventions or even modifying parts of our code many times over. Thus, it’s best to target short, straightforward, and most readable version of our components and move other codes elsewhere to ensure they’re not an annoyance to locate, replicate or amend.</p><p>Unlike the olden days of coding the web of HTML, JS and CSS as separate entities, modern JavaScript libraries and frameworks such as ReactJS, Angular and Vue integrate much better with the site markup and design — empowering the developer with an elegant yet simpler coding procedure. They also come with powerful features and tools that let us organize the codes to ensure an efficient and a pleasant development experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E9rJyc0GUM9-wNFBntTBCQ.jpeg" /></figure><p>My experience with ReactJS dates back only 9 months (and with PHP, prior to that) since when I’ve coded three (2 medium, 1 large scale) projects. So far I’ve learnt many things about it that I wish somebody told me when I got started with it. Here, I’ve compiled a list of seven tips explaining some useful coding methods for beginners of JavaScript — especially with ReactJS.</p><h3>1. Use a Robust IDE.</h3><p>For front-end web development in 2018, IntelliJ WebStorm is the real deal. Try and make use of as many features it offers as possible. Here are some useful ones that I make frequent use of:</p><p><strong>a. </strong>Shortcut keys (eg. find everything, auto-indent, quickly switch between files, search, SCSS compiler, etc)</p><p><strong>b. </strong>Auto import + Custom Import Snippets</p><p><strong>c. </strong>File Watchers</p><p><strong>d. </strong>Version Control</p><p><strong>e. </strong>Local History</p><p><strong>f. </strong>Debugging</p><p><strong>g. </strong>Testing</p><p><strong>h. </strong>Snippets.</p><p><strong>Examples:</strong></p><ul><li>console.log(‘users received’, ) -&gt; shortcut: con[Tab]</li><li>component class boilerplate -&gt; shortcut: imp[Tab]</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fabca976adefd05ffae36caf66977d45/href">https://medium.com/media/fabca976adefd05ffae36caf66977d45/href</a></iframe><h3>2. Choose a proper directory hierarchy for file management.</h3><p>Organize the project files in appropriate directories in the manner that seems most meaningful to you in order to be able to locate the files faster when you need them. For a typical medium to large scale web-apps built with ReactJS and Redux, you might begin with the following basic directory and file tree.</p><pre>dist/<br>node_modules/<br>src/<br>    actions/<br>    assets/<br>        css/<br>        fonts/<br>    components/<br>        pages/<br>        shared/<br>        App.js<br>    helpers/<br>    reducers/<br>        reducers.js<br>    translations/<br>    store.js<br>    config.js<br>    routes.js<br>    index.js<br>package.json<br>webpack.config.js</pre><h3>3. Follow a common convention pattern for files, components names, functions and variables</h3><p>A good file, class, function and variable name clarifies its purpose at a glance. It’s possible to use any naming convention supported by language syntax. Below are commonly used naming rules I prefer in my react-redux application.</p><p><strong>a. </strong>Component class names with first letters of words in uppercase with no spaces or dashes between them</p><ul><li>CreateUser.js &lt;CreateUser/&gt;</li><li>FoodMenu.js &lt;FoodMenu/&gt;</li></ul><p><strong>b. </strong>General Component Class Functions and Variables in camelCase.</p><ul><li>function renderUsersList() { return .. }</li><li>onSubmit() { return .. }</li><li>let selectedCategories = [];</li></ul><p><strong>c. </strong>Functions that render JSX create DOM elements. Hence, to clarify it does that, name them differently from regular functions. e.g. in all lowercase letters separated by an underscore.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8091df52d7908a6a626a54e1cc7c3d8c/href">https://medium.com/media/8091df52d7908a6a626a54e1cc7c3d8c/href</a></iframe><p><strong>d. </strong>For variable names with two words, avoid userid / userId / userID but use user_id (or whatever you prefer, but in common), preferably in both the server and client.</p><p><strong>e. </strong>Redux Action names in lowercase, separated by an underscore; beginning with the action name and ending with the request type. If data is a single subject, use singular else plural.</p><p><strong><em>subject_action.js</em></strong></p><ul><li>user_get.js (Single order)</li><li>users_get.js (Multiple users)</li><li>permission_put.js</li><li>food_delete.js</li></ul><p><strong>f. </strong>Redux Reducer follows implemented similarly as actions but with words separated by dashes.</p><p><strong><em>subject-action.js</em></strong></p><ul><li>users-get.js</li><li>food-delete.js</li></ul><h3>4. Break-down codes into as many re-usable components as possible.</h3><p>We can understand our ReactJS JSX code as web-components that are essentially, re-usable files containing classes or functions containing closely-related codes - often placed in separate files of their own. They are placed in the UI as distinct elements capable of re-rendering on their own on data change without affecting other components. Web-components contain purely component related code within them and are kept as compact as possible by moving unrelated codes elsewhere as importable variables or functions. eg. helpers, reducers or actions, node_modules, etc. There is no definite rule for what we should create components out of but it’s best to avoid large components and break them down into as many reusable individual components as possible, without worrying about how small they are.</p><p>What can we make components out of?</p><p>Lower level HTML DOM Elements like:</p><ol><li>Buttons</li><li>Buttons, Badges, Icons</li><li>Form Inputs, Labels</li><li>Sidebars and Navigation Menus, Header and Footer</li><li>Cards and Panels</li><li>Alerts, Popups and Snackbars</li><li>Pages that render on route change</li><li>Any other distinct UI element(s)</li><li>Other components</li></ol><p>Component Examples:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfd20ff86e1eb26fac029fc5dc954ae2/href">https://medium.com/media/bfd20ff86e1eb26fac029fc5dc954ae2/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f9564e6755c10ec274c16774b95031b/href">https://medium.com/media/6f9564e6755c10ec274c16774b95031b/href</a></iframe><p>Some examples of component usage:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b54509363bf0dc6fb61be3504c9e5f1/href">https://medium.com/media/5b54509363bf0dc6fb61be3504c9e5f1/href</a></iframe><p>A smaller and cleaner component can be achieved by moving lower-level codes somewhere as an importable function, usually in a helper. If the function manipulates data and its structure, they can go in redux reducers and actions. In the following example, we create a re-usable helper function `inRecord` that takes in an array of objects and checks the array for presence of any data for any condition, returns a Boolean result.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52e06d6faf8cbfc9aa23df1362f76194/href">https://medium.com/media/52e06d6faf8cbfc9aa23df1362f76194/href</a></iframe><p><strong>Pros of Componentization:</strong></p><p><strong>a. </strong>Less coding because of higher component re-usability</p><p><strong>b. </strong>Faster development speed</p><p><strong>c. </strong>Less debugging time</p><p><strong>d. </strong>Ease of implementation of new features since a change in one place is reflected in many.</p><p><strong>e. </strong>Easier to read your own or a friend’s code</p><p><strong>Cons of Componentization:</strong></p><p><strong>a. </strong>Need to create many files.</p><p><strong>b. </strong>Need of a powerful IDE with excellent provision of as many features as possible.</p><p><strong>c. </strong>Need to re-think conventional JavaScript program flow and coding paradigms.</p><h3>5. Order of component methods:</h3><p>As the component size grows, it will get harder to find functions within the file; hence it’s good to declare different types of functions in order of their functionality.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73de794fd6bd240e5aba58f97d603b6c/href">https://medium.com/media/73de794fd6bd240e5aba58f97d603b6c/href</a></iframe><p>Tip: Declaring a constructor in the beginning of the component can be skipped if you simply want to do these:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b512790c668c2ad4ed1946411db71d2/href">https://medium.com/media/4b512790c668c2ad4ed1946411db71d2/href</a></iframe><h3>6. Use Helpers</h3><p>Helpers help reduce the amount of code in the components by making use of re-usable functions and constants for a more practical program workflow. Here are some sample helpers to give you an idea of what helpers to create.</p><p><strong>Local Storage Helper</strong> — Shortcuts for localStorage.getItem() or localStorage.setItem()</p><p><strong>Meta Helper</strong> — JavaScript language shortcuts. eg. getByID(el) -&gt; document.getElementById(el)</p><p><strong>Data Helper</strong> — Static JS data list Objects for anything like countries, languages, etc.</p><p><strong>Form Helper</strong> — Validation rules functions, error handlers, etc</p><p><strong>JSX Helper</strong> — Frequently used JSX Elements exported as functions</p><p><strong>General Helper</strong> — Regex functions, scrollToErrors(), scrollToTop()</p><h3>7. Use a Config file</h3><p>It can be useful to store all front-end configuration and static data for the project in a global, exportable const object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e7d175be3857e8544d57e807fbb1fa4/href">https://medium.com/media/5e7d175be3857e8544d57e807fbb1fa4/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=416739947b50" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hazesoft/efficient-code-organization-in-reactjs-416739947b50">Efficient Code Organization in React-Redux</a> was originally published in <a href="https://medium.com/hazesoft">Hazesoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>