Framework Guides

icon picker
React Guidelines

image.png

Introduction

React is a JavaScript libraray for rendering user interfaces (UI). UI ias built from small units like buttons, text, and images. React lets you combine them into reusable, nestable components. From web sites to phone apps, everything on the screen can be broken down into components. ()

General Guidelines

Start with a static mock of your component whenever possible as this helps us identify key features and gives structure to your application.
Break The UI Into A Component Hierarchy, identifying components, common elements and required functionality.
Use Functional Components instead of classes — Functional components are the stateless component that simply accepts data and display the output in some form, while Class components are stateful components that implement logic and state.
Use SCSS/CSS for global/reusable styles across teams, platforms and components. Avoid using styled-components, or CSS-in-JS for creating stylesheets
To make components reusable, break the larger component into smaller ones. That means instead of putting multiple functionalities in one component create one component that will be responsible for single functionality, the principle is called as “single responsibility principle”.
To minimize the component complexity, it is always a good practice to isolate your stateful data-loading logic from the rendering stateless logic.
Avoid using Indexes as a Key Props According to React document, Key props help react to identify which item has been changed, added, or removed. Therefore, the key should be given to the element inside the array to give the elements a stable identity.
A properly maintained folder and file structure help you to understand project flow and simplify code maintenance and extraction to any other project.
Always follow naming conventions outlined by your team. Following naming conventions ensures users know how to name digital assets so that they will remain consistent and correct.
Testing ensures code integrity. Therefore it is good practice to create a Test directory within your component’s directory to perform all the required tests and ensure that the addition of new code will not break the existing functionality.
Understand Composition vs Inheritance in React and how it affects react development.
Develop

Deep Dive - React Development

Component Driven Development (CDD)


Components enable interchangeability by isolating state from application business logic. That way, you can decompose complex screens into simple components. Each component has a well-defined API and fixed series of states that are mocked. This allows components to be taken apart and recomposed to build different UIs. ()

image.png
Build one component at a time - Build each component in isolation and define its relevant states. Start small.
Combine components - Compose small components together to unlock new features while gradually increasing complexity.
Assemble pages - Build pages by combining composite components. Use mock data to simulate pages in hard-to-reach states and edge cases.
Integrate pages into your project - Add pages to your app by connecting data and hooking up business logic. This is when your UI meets your backend APIs and services.
CDD links and resources

Developing Components in Isolation

Modern UIs are more complicated than ever. It is critical that you have confidence in your code. Developing and testing your UI components in isolation allows you to accomplish that.
image.png

REACT Components

React component libraries are becoming increasingly popular, and for good reason. They are great tools that guarantee consistency and reusability of UI elements both within and across digital products, all while having the potential to significantly reduce development time and effort.
image.png
When you started your last software project, did you write your own programming language first? Did you build your computer from scratch? Of course not. That would be ludicrous. It would be a waste of time (and in sustainable business that means money). It's not your core competency. It's not your value proposition. You'd run out of money before you finished.
Recommended Components

Javascript Libraries
(included in the react-create-app)

Articles

Miscellaneous

Code Examples

TBD

Foundations

If you need more information about the guidelines or you're not comfortable with subject matter, you can browse the following resources
When you work with large projects, it's important that you remain consistent throughout the codebase and follow the best practices.
(Official)
Headless component libraries:
These component libraries come with their components un-styled. If you have a specific design system to implement, it might be easier and better solution to go with headless components that come unstyled than to adapt a styled components library such as Material UI to your needs. Some good options are:
As your application grows, it helps to be more intentional about how your state is organized and how the data flows between your components. Redundant or duplicate state is a common source of bugs. UNderstand how to structure your state well, how to keep your state update logic maintainable, and how to share state between distant components.
(React docs)
Routing
Routing is a way of organizing and managing application states. A routing framework in JavaScript helps you to change the state of the application--perhaps moving from one admin panel section to another--while maintaining application persistence.
Always use a routing library to handle application routing to for all react applications
Take advantage of features like query params, search-params, history management, etc. Most routing libaries have these features built s.
RECCOMENDATION: Declarative routing for React apps at any scale

TBD


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.