{"id":12009,"date":"2019-07-05T09:40:03","date_gmt":"2019-07-05T06:40:03","guid":{"rendered":"https:\/\/railsware.com\/blog\/?p=12009"},"modified":"2021-04-05T16:53:22","modified_gmt":"2021-04-05T13:53:22","slug":"why-use-react","status":"publish","type":"post","link":"https:\/\/railsware.com\/blog\/why-use-react\/","title":{"rendered":"Why Use React JS?"},"content":{"rendered":"<p class=\"intro-text\">At Railsware, we always aim to use the best pieces of stack out there. This allows us to quickly build great, robust products and iterate on them rapidly. Our engineers are also encouraged to experiment with new technologies so it should come as no surprise that a few years ago ReactJS started quickly conquering our codebase. Since most of our products these days ship with React under the hood, we feel it\u2019s about time to share why we use ReactJS in our projects.<\/p>\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2019\/07\/Why-we-use-ReactJS-for-our-projects-Illustration.jpg\" alt=\"Why we use ReactJS\" width=\"2400\" height=\"1260\" class=\"alignnone size-full wp-image-12017\" srcset=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2019\/07\/Why-we-use-ReactJS-for-our-projects-Illustration.jpg 2400w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2019\/07\/Why-we-use-ReactJS-for-our-projects-Illustration-360x189.jpg 360w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2019\/07\/Why-we-use-ReactJS-for-our-projects-Illustration-768x403.jpg 768w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2019\/07\/Why-we-use-ReactJS-for-our-projects-Illustration-1024x538.jpg 1024w\" sizes=\"auto, (max-width: 2400px) 100vw, 2400px\" \/><\/p>\n\n<h2>Why use ReactJS? What is it in the first place?<\/h2>\n\n<p>While often considered a JavaScript framework like Angular or Vue.js, React is actually a frontend open source library. It\u2019s used specifically for large, complex web interfaces as well as single-page applications. Created first by Jordan Walke, a software engineer at Facebook, it was quickly implemented in Facebook\u2019s newsfeed back in 2011. A year later Facebook\u2019s Instagram.com followed, and that\u2019s when it all started. These days, hundreds of thousands (if not millions) of websites are powered by this library and thousands more are born every single day.<\/p>\n\n<p>In fact, ever since the launch of React, we\u2019ve seen an explosive growth in the usage of lightweight but powerful JavaScript libraries. Users more and more often want to use faster, more dynamic web pages, while developers opt for modern and flexible environments without tons of boilerplate in the package. That\u2019s why ReactJS is an obvious choice for many. To explain why, let\u2019s go over the top reasons why we use React.<\/p>\n\n<h3>Simplicity<\/h3>\n\n<p>The first thing that gets so many people to use ReactJS in their projects is probably its simplicity. React is a JavaScript library so if a developer is familiar with JS functions, they will have an easier start with ReactJS.<\/p>\n\n<p>With this library, developers define interfaces with an HTML-like syntax called JSX. As a result, HTML and CSS code is produced. React\u2019s API is very small, yet powerful, and all you need to do before you start is to learn a few basic functions.<\/p>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">const AppHeaderBlock = () => (\n  <div>\n    <BrandedHeader>Inventory<\/BrandedHeader>\n    <ul className=\"menu\">\n      <li className=\"nav-item\">\n        <button onClick={gotoHome}>Home<\/button>\n      <\/li>\n      <li className=\u201dnav-item\u201d>\n        <button onClick={gotoAccount}>Account<\/button>\n      <\/li>\n    <\/ul>\n  <\/div>\n)\n<\/pre>\n\n<p><em>The example of a React component, implemented in JSX.<\/em><\/p>\n\n<p>A little bit of a learning curve appears when you want to use React with other JS libraries, such as Redux, Material UI or Enzyme. While not a part of the React stack, such libraries add additional capabilities and allow you to manage React components more easily. The most common libraries are well documented and should cause no trouble to any developer.<\/p>\n\n<p>Simplicity of React comes with certain benefits for businesses. Those already relying on other JavaScript frameworks will have an easier transition to React. Even if your goal is to just try the library, without committing to a full-fledged transition, this also won\u2019t be difficult. And if you need to scale in the future or change the development team, the abundance of ReactJS developers on the market will make things a lot easier. You can check out marketplaces such as <a href=\"https:\/\/youteam.io\/blog\/hiring-senior-react-developer\/\" rel=\"noopener noreferrer\" target=\"_blank\">YouTeam<\/a> for more information.<\/p>\n\n<h3>Developers love it<\/h3>\n\n<p><br>\nTrue story. <a href=\"https:\/\/2020.stateofjs.com\/en-US\/technologies\/\" rel=\"noopener nofollow noreferrer\" target=\"_blank\">The recent research<\/a> performed by StateofJS.com shows that JavaScript developers are really happy about using React in their projects, comparing it favorably to its closest competitors such as Angular or Vue.js (Check out a <a href=\"https:\/\/railsware.com\/blog\/react-vs-angular-battle-for-the-front-end\/\" rel=\"noopener noreferrer\" target=\"_blank\">detailed comparison of ReactJS vs Angular<\/a>). What\u2019s more, at the time of writing, nearly two-thirds of thousands asked said that they used ReactJS and would use it again.<\/p>\n\n<p>This should have gigantic meaning for anyone planning to run any software product for the next few years. If developers are so excited about React, this means there will be more and more of them out there. This, as a result, means that there will be big ecosystem of various React libraries and tools to enhance the development. As a result, ReactJS will become more powerful with each one added. There will also be a lot of talent on the market, ready to build new projects and support existing ones. ReactJS is here to stay.<\/p>\n\n<h3>Reusable elements<\/h3>\n\n<p><br>\nThis is where the real beauty of React comes from. If you\u2019ve ever used some design tools like Sketch, you must know how easy and intuitive building interface elements is. You draw a rectangle and resize it to your liking. You then insert some copy inside and group them together  as a \u2018text field\u2019. Then, you duplicate the group several times, draw an attention-grabbing button with  copy and wrap it all up with a frame and a header. You then group it all as a \u2018contact form\u2019. Whatever business this project is for, you\u2019ll likely reuse this contact form multiple times throughout the project. It absolutely doesn\u2019t make sense to design the form from scratch every time you need one so obviously a decent designer will just insert already grouped elements with just a few clicks.<\/p>\n\n<p>Development used to be much more complex than that but ReactJS gives us the tools to do exactly the same thing. Each React project is built using the so-called reusable components. This means that each element of the interface that you\u2019ve already built, can be used anywhere in your project by just calling from other components. You write such a function once and can reuse it anywhere. What\u2019s more, you can group these elements into sections or pages and insert them anywhere around the project with the same functions.<\/p>\n\n<p>Reusable elements in ReactJS also follow a simple mental model. If a component is given the same data multiple times, it will always yield the very same set of HTML and CSS. Such capability, called idempotence, makes it <a href=\"https:\/\/www.freecodecamp.org\/news\/what-does-it-mean-when-code-is-easy-to-reason-about-4e6f63eb386f\/\" rel=\"noopener nofollow noreferrer\" target=\"_blank\">easy to reason about<\/a> and to test.<\/p>\n\n<p>Consider this common example: all of the buttons in your application must be styled in the same way. In ReactJS, you can define a component and reuse it anywhere instead of copy-pasting the same code over and over again.<\/p>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">const BrandedButton = ({icon, title, onClick}) => (\n  <button className=\"branded-button\" onClick={onClick}>\n    <img src={icon} className=\u201dicon\u201d \/>\n    {title}\n  <\/button>\n)\n\/\/ from now on, use it as:\n<BrandedButton icon=\u201dlogin\u201d title=\u201dLog in\u201d onClick={gotoLogin} \/><\/pre>\n\n<p>Besides being easier to write (and read), this component brings a very important benefit: its presentation is separated from its semantics. Designers are free to build a component library without worrying about business logic and engineers can construct interfaces from the components, knowing they\u2019ll look good without any effort.<\/p>\n\n<p>All of these come with a lot of advantages for any business. Thanks to reusable components, your platform is consistent and, as a result, easy to navigate for users. There\u2019s less code to be written without losing any functionalities and this inevitably leads to faster development. It\u2019s also simpler to add new features and test them as you have <a href=\"https:\/\/storybook.js.org\/\" rel=\"noopener nofollow noreferrer\" target=\"_blank\">tons of code already written and ready to be reused<\/a>.<\/p>\n\n<h3>Easy to update components, individually or in bulk<\/h3>\n\n<p><br>\nReactJS also allows you to quickly iterate on any element. You want to modify the colour of all buttons throughout the website? A few seconds and it\u2019s done. Want to stop redirecting from each case study to an outdated landing page? Swapping all the old links with the new ones is a breeze. Of course, if you wish to only modify one or a few of components, you can do it without affecting any other elements of your project.<\/p>\n\n<p>The logic behind each component can be defined by a developer once and React will just use it to display elements exactly where we wanted them to be, across the entire project. For example, avatars can have the same hover or onClick behaviours throughout the website. It might not seem like a big difference but for anyone used to having 5-10 different ways of showing users\u2019 avatars, it is! Another example can be formatting dates in a desirable format. As long as a single component is used for that, the format will be consistent on the entire project. Maintaining the code base just got a lot easier!<\/p>\n\n<h3>Virtual DOM<\/h3>\n\n<p><br>\nIn many front-end frameworks, DOM (Document Object Model) is a tree-shaped HTML representation of all elements of a web application, built into a parent-child structure. Whenever there is a change in the state of any element (for example, a button is clicked or a form submitted), DOM gets immediately updated. This way, it always represents the current UI of a website. A single manipulation of a DOM is fast. But with every change, both a parent and its children get updated. It\u2019s fine on simple websites but once a project gets complex, it causes very frequent updates to multiple elements, effectively slowing down the website. This, as a result, makes for a rather poor user experience.<\/p>\n\n<p>ReactJS optimises this by leveraging its Virtual DOM to speed up the websites. Virtual DOM (vDOM), as the name suggests, is not a real DOM but its virtual representation. Whenever any element of a website is modified, a vDOM is updated. The updated VDOM is then compared against a real DOM using a reconciliation algorithm from React. This process is used to calculate the minimal set of changes to be applied to the actual DOM. Rather than update dozens of elements whenever a change is made, ReactJS updates only a single element that was just modified, significantly cutting the time of the operation.<\/p>\n\n<p>As a result, it speeds up the page significantly. It\u2019s hardly a secret that faster pages tend to result in higher conversion rates and better user experience. This, consequently, tends to bring higher sales, more signups and lower drop off rates.<\/p>\n\n<h3>React Native and Mobile Apps<\/h3>\n\n<p><br>\nA revolutionary thing that came with React was the ability to build mobile iOS and Android apps, without the need to hire new developers. React\u2019s port to mobile, known as <a href=\"https:\/\/railsware.com\/blog\/react-vs-react-native-development-whats-the-difference\/\" rel=\"noopener noreferrer\" target=\"_blank\">React Native<\/a>, lets you write fully featured, fully native mobile applications in Javascript. This lets developers reuse code from your web application in ReactJS to speed up mobile development. Everything but the presentation can be shared with the mobile app. A ReactJS developer might also use various JS libraries that they\u2019re already familiar with. Once a shared codebase is ready, a developer starts building native iOS or Android components. Despite differences between both platforms, a good React developer can handle all platforms after a bit of research.<\/p>\n\n<p>While there\u2019s a lot of discussion on whether such apps can replace native apps (we covered <a href=\"https:\/\/railsware.com\/blog\/react-native-vs-native-app-development-ios-and-android-in-one-go\/\" rel=\"noopener noreferrer\" target=\"_blank\">the React Native vs Native App development comparison<\/a>), we believe React Native apps are a great addition to a web project. Such development significantly cuts Time to Market and lets you outpace the competitors at no additional expense. You\u2019ll still need to write a bit of platform-specific code but you\u2019ll also get to reuse many components, saving you even more time.<\/p>\n\n<h2>When to use ReactJS?<\/h2>\n\n<p>The above mentioned reasons make for a compelling case to use React in many different scenarios. The obvious choice will be sites relying heavily on user interaction with the elements. This will be especially true if the state of components frequently changes &#8211; navigation pops up and disappears, users log in, content or e.g. buttons change after users\u2019 interaction. Thanks to Virtual DOM, React will be able to manage each of these changing states easily and dynamically present the content to end users.<\/p>\n\n<p>React will be also a great choice if a website comes with a very complex structure that might be hard to keep track of with a traditional, imperative approach. As the application scales, React will allow you to easily keep track of all the interactions.<\/p>\n\n<h2>When not to use ReactJS?<\/h2>\n\n<p>Over the years, the React library became so robust and flexible that it can be used for nearly any frontend project. There might be, however, cases when using React is possible but there are likely just better suited approaches. This will mostly apply to very simplistic pages with few elements, such as landing pages or simple websites with little customization or without lots of dynamic content and rich stateful interactions. For such projects, a simple HTML generated by a backend and a bit of JavaScript might be enough. With the abundance of simple and inexpensive web generators, such sites can be brought to life in no time. Deploying ReactJS could be simply overkill. But, if you plan to add much more interaction to the website in the near future, go for ReactJS from the beginning.<\/p>\n\n<p>Don\u2019t use React with heavy, complex admin panels. A much better approach are typical backend frameworks that are more tightly coupled to database structure. React works best with a lot of workflows and interactions, you likely won\u2019t need much of that. To code typical admin panel functionalities such as tables or user permissions, backend frameworks will require much less code than framework-focused ReactJS. As such, it might be easier to stick with backend frameworks from the get-go and keep React for more frontend-focused developments.<\/p>\n\n<p>Finally, as mentioned in the beginning React is fairly easy to learn for any JavaScript developer. There is, however, a higher learning curve if your developers never worked with JS before and it\u2019s something to consider. ReactJS follows the flux architecture and this concept might be harder to grasp for developers used to different approaches (like MVC for example).<\/p>\n\n<h2>Summary<\/h2>\n\n<p>ReactJS is in many ways a revolutionary approach to building both frontend and mobile apps. It\u2019s quickly grown to be the favourite tool for many JavaScript developers and it looks like it\u2019s here to stay. We absolutely love using it with our products and will definitely continue doing so for years to come. If you\u2019re still hesitating between React and other frameworks\/libraries, give us a shout and we\u2019ll be happy to suggest the best approach.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are many reasons why ReactJS is our favourite JavaScript library. If you&#8217;re still not sure whether it will work for your project, check out our article!<\/p>\n","protected":false},"author":77,"featured_media":12018,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3],"tags":[],"coauthors":["Piotr Ma\u0142ek"],"class_list":["post-12009","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"acf":[],"aioseo_notices":[],"categories_data":[{"name":"Engineering","link":"https:\/\/railsware.com\/blog?category=development"}],"post_thumbnails":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2019\/07\/Why-we-use-ReactJS-for-our-projects-Illustration.jpg","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/12009","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/comments?post=12009"}],"version-history":[{"count":15,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/12009\/revisions"}],"predecessor-version":[{"id":13711,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/12009\/revisions\/13711"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media\/12018"}],"wp:attachment":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media?parent=12009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/categories?post=12009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/tags?post=12009"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/coauthors?post=12009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}