
{"id":12050,"date":"2022-02-07T13:58:16","date_gmt":"2022-02-07T12:58:16","guid":{"rendered":"https:\/\/careerfoundry.inbearbeitung.de\/en\/?p=12050"},"modified":"2023-08-30T13:10:08","modified_gmt":"2023-08-30T11:10:08","slug":"what-is-reactjs","status":"publish","type":"post","link":"https:\/\/careerfoundry.inbearbeitung.de\/en\/blog\/web-development\/what-is-reactjs\/","title":{"rendered":"What is React.js? A Beginner's Guide"},"content":{"rendered":"<p><strong>You might have heard a lot about React.js. It isn\u2019t a programming language or framework, nor is it a runtime environment <a href=\"https:\/\/careerfoundry.inbearbeitung.de\/en\/blog\/web-development\/what-is-nodejs\/\">like Node.js<\/a>. So what is it really, and how do you use it?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">React is a <strong>JavaScript <\/strong><\/span><b>library<\/b><span style=\"font-weight: 400;\"> used to build <a href=\"https:\/\/careerfoundry.inbearbeitung.de\/en\/blog\/ui-design\/what-is-a-user-interface\/\" target=\"_blank\" rel=\"noopener\">user interfaces<\/a> on the frontend. An open-source project originally created by Facebook, it&#8217;s one of the most popular JavaScript libraries, with over 180,000 stars on Github. <\/span><\/p>\n<p>In the <a href=\"https:\/\/2022.stateofjs.com\/en-US\/libraries\/\" target=\"_blank\" rel=\"noopener\">2022 State of JS Survey<\/a> it was voted the library with the highest user count\/retention score, making it an incredibly safe bet to learn.<\/p>\n<p><span style=\"font-weight: 400;\">The goal of React is to allow developers to quickly build out their interfaces.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To explain all about React.js, we\u2019ll start by introducing JavaScript libraries themselves. Next, we\u2019ll learn more about React by exploring what it was designed as a solution to, and its major features such as components. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Once we\u2019ve covered these, we\u2019ll teach you when is the best situation in which to employ React. Although this technology is widespread these days, we\u2019ll give you some concrete examples of companies which have employed it in building their websites.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you\u2019d prefer to skip ahead to a certain section, simply use the clickable menu:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"#what-is-a-javascript-library\">What is a JavaScript library?<\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"#what-problem-does-reactjs-solve\">What problem does React.js solve?<\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"#features-of-react\">Features of React<\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"#what-are-react-components\">What are React components?<\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"#when-should-you-use-react\">When should you use React?<\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"#which-companies-use-react\">Which companies use React?<\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"#final-thoughts\">Final thoughts<\/a><\/li>\n<\/ol>\n<h2 id=\"what-is-a-javascript-library\"><span style=\"font-weight: 400;\">1. What is a JavaScript library?<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Often when writing code, you need <a href=\"https:\/\/careerfoundry.inbearbeitung.de\/en\/blog\/web-development\/introduction-to-javascript\/\">JavaScript to perform repetitive functions<\/a>. For example, when you type in a search bar you want it to give you suggestions. You also want the search button to change color when you hover over it.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you use this search bar all over your website, this could get annoying to write over and over again. This is where libraries become useful.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A JavaScript library is a collection of pre-written JavaScript code. Rather than coding repetitive functions by hand, you can add them to a library or use someone else\u2019s. Import the library into your project rather than hand-writing repetitive code yourself.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">There are libraries for most common problems you come across as a developer. Everything from formatting dates to performing common mathematical calculations has a library, with one of the most common <a href=\"https:\/\/careerfoundry.inbearbeitung.de\/en\/blog\/web-development\/javascript-vs-jquery-whats-the-difference\/\">frontend JavaScript libraries being JQuery<\/a>.<\/span><\/p>\n<h2 id=\"what-problem-does-reactjs-solve\"><span style=\"font-weight: 400;\">2. What problem does React.js solve?<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Before React, JavaScript developers were building user interfaces by hand using vanilla JavaScript. In case you&#8217;re not sure, vanilla JavaScript means JavaScript without any additional libraries or frameworks.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">While we advise <a href=\"https:\/\/careerfoundry.inbearbeitung.de\/en\/blog\/web-development\/should-you-learn-javascript\/\">coding with vanilla JavaScript at the start<\/a>, for professional developer teams this meant longer development times and more opportunities for errors and bugs.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In 2011, developers at Facebook created React to solve issues with code maintenance. Because of this, you&#8217;ll find that React has some excellent documentation <a href=\"https:\/\/reactjs.org\/docs\/getting-started.html\" target=\"_blank\" rel=\"noopener\">on its official website<\/a>.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Only eleven years later it&#8217;s the most-desired web framework according to the <a href=\"https:\/\/survey.stackoverflow.co\/2023\/#section-admired-and-desired-web-frameworks-and-technologies\" target=\"_blank\" rel=\"noopener\">2023 Stack Overflow Developer Survey<\/a>.<\/span><\/p>\n<h2 id=\"features-of-react\"><span style=\"font-weight: 400;\">3. Features of React<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">There are two major features of React that aim to improve the developer experience: JSX and Virtual DOM. Let&#8217;s briefly take a look at them:<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">JSX<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">At the center of any web application are HTML (Hypertext Markup Language) documents.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"> <a href=\"https:\/\/careerfoundry.inbearbeitung.de\/en\/blog\/web-development\/what-is-html-a-beginners-guide\/\">HTML is a formatting system<\/a> used to structure a web page and its content. While reading the HTML, browsers create something called a Document Object Model (DOM). The <\/span><b>DOM<\/b><span style=\"font-weight: 400;\"> views an HTML document as a tree of nodes where each node is an HTML <\/span><b>element<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Web content these days is dynamic. It changes depending on the behavior, preferences and interests of the user. JavaScript is what allows you to modify the DOM to add dynamic content.\u00a0\u00a0<\/span><\/p>\n<p><b>JSX<\/b><span style=\"font-weight: 400;\"> (stands for JavaScript eXtension) lets you change the DOM with HTML-style code. It&#8217;s one of the reasons people love React so much. JSX is easier to write and understand compared to OG vanilla JavaScript elements.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Not only that, but JSX leads to significant performance improvements and is compatible with all browsers. On top of that it also delivers increased efficiency in the development workflow.\u00a0<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Virtual DOM<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">We&#8217;ve talked about the DOM, but what is the <strong>virtual<\/strong><\/span><span style=\"font-weight: 400;\"> DOM? To get there, let&#8217;s first discuss why we might want a virtual DOM.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So you have your web page. Its DOM is made up of HTML elements. Let&#8217;s say your website has a lot of dynamic content and it&#8217;s popular, so there&#8217;s a lot of user interaction.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To update the DOM without the user having to refresh the page to see changes, the entire DOM has to reload. This is very inefficient, but without it the user will have a bad experience.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Enter the Virtual DOM. If the page is using JSX elements, React will create a copy of the DOM, called a Virtual DOM.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This Virtual DOM keeps track of the elements the user interacts with and only updates the ones that are relevant. Since we&#8217;re not reloading the entire DOM on each interaction, this improves performance.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, say you&#8217;re on Facebook and you comment on someone&#8217;s post. Without the virtual DOM, the whole page would reload so you can see your comment appear on the screen.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">With the virtual DOM, React scans the page and identifies which DOM section changed. You&#8217;ll then see your comment appear, and only that comment section of the DOM is updated.<\/span><\/p>\n<h2 id=\"what-are-react-components\"><span style=\"font-weight: 400;\">3. What are React components?<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">A core concept of React.js is <\/span><b>components<\/b><span style=\"font-weight: 400;\">. Components are the building blocks that make up a React application. Developers break up the user interface into reusable chunks of code. For example, you might have a &#8220;Search Bar&#8221; or a &#8220;Shop Item&#8221; component.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">On an e-commerce site, for example, you have many individual item pages for each product. Each product has an image, price, and color. Rather than create each individual item page, you create one item component and reuse it.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Each component has its own set of properties and functions (i.e. your price, color, etc.). Data flows from parent to child component to define values. In this case, your parent component is your product list. Your top level component is your \u201cApp\u201d component.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">State<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">State management is a big concept in React, but what is state? State is an object. It stores a set of observable properties that control the behavior of the component. This information can change as the user interacts with the user interface.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s look at the example of our e-commerce site again. You&#8217;re browsing through a list of products. This list spans multiple pages and allows you to sort by values like type of item, price and color.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">After the first page, you click to go to the second. Then you decide you actually want to see only items that are green. We store this pagination (page 2) and sorting information (green) in the state.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Props<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Short for properties, props allow the user to pass data or arguments to React components. While state can change, props are read-only and cannot be changed. Props help make a React component more dynamic.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We&#8217;ve talked a bunch about how React is great because it allows us to reuse code, i.e. components. As we use our components again and again in our UI, we don&#8217;t generally need the component with the same data.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Back to our product list page. We need to change the content of the component depending on the product selected by the user. This is where props come in.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When the user clicks a product from the product list page, it renders the product item component. This parent component (item list) passes props down to its child component (product item). The component has the same structure, but its content changes depending on its props. These props might be data like price, color, availability.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Similarly, if the product is unavailable, we can pass that info down to the product item component. The item page can then render an email box for you to enter your email to be notified when it&#8217;s back in stock.\u00a0<\/span><\/p>\n<h2 id=\"when-should-you-use-react\"><span style=\"font-weight: 400;\">4. When should you use React.js?<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">If you have a team of developers who are familiar with JavaScript, React could be a great option. Especially if your application is complex, consider React.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you only need to build a simple static website however, React might be overkill. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s say you have a page for a restaurant that has only the menu, opening times and contact information. To set up all the boilerplate React code for that wouldn&#8217;t make sense.<\/span><\/p>\n<p>As you&#8217;ve seen already though, for every other situation it&#8217;s a great tool to have in your kit.<\/p>\n<p>This is why you&#8217;ll not just learn it as part of the CareerFoundry Web Development Program, but also deploy it in your projects. if you&#8217;re interested, then check out software engineer and program graduate Lucian talks us through <a href=\"https:\/\/careerfoundry.inbearbeitung.de\/en\/portfolios\/lucian-murmurache\/\" target=\"_blank\" rel=\"noopener\">how he created a native app called ChatMeApp<\/a> using React for his portfolio.<\/p>\n<p>Another similarly popular JavaScript technology also use to build applications is Angular. Learn just what it is, and when to use it in <a href=\"https:\/\/careerfoundry.inbearbeitung.de\/en\/blog\/web-development\/angular-vs-react-guide\/\" target=\"_blank\" rel=\"noopener\">our guide to Angular vs React<\/a>.<\/p>\n<h2 id=\"which-companies-use-react\"><span style=\"font-weight: 400;\">5. Which companies use React?<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">React is popular among a lot of top companies you use every day. The creators of React\u2014Facebook, Instagram, etc\u2014are obvious examples. Here are some other companies that use React.js:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Pinterest<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Shopify<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Amazon<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Asana<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Atlassian<\/span><\/li>\n<\/ul>\n<h2 id=\"final-thoughts\"><span style=\"font-weight: 400;\">6. Final thoughts<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">React.js is a great option for JavaScript developers creating single-page web applications. It allows developers to create complex websites using reusable components. A major benefit is the ability to update <\/span><b>only<\/b><span style=\"font-weight: 400;\"> the component with the relevant data. Rather than reload the whole page, React will keep track via its Virtual DOM exactly what has changed.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">It\u2019s fast, scalable and flexible due to it being a library rather than a more opinionated framework. It also has a huge and active developer community, and pretty great documentation. Definitely give it a try in your next project!<\/span><\/p>\n<p>If you&#8217;d like to read more about JavaScript and the world of web development in general, then these articles should interest you:<\/p>\n<ul>\n<li><a href=\"https:\/\/careerfoundry.inbearbeitung.de\/en\/blog\/web-development\/django-framework-guide\/\">What Is the Django Framework? The Complete Beginner\u2019s Guide<\/a><\/li>\n<li><a href=\"https:\/\/careerfoundry.inbearbeitung.de\/en\/blog\/web-development\/python-3-8-advantages\/\">The Advantages of Python 3.8<\/a><\/li>\n<li><a href=\"https:\/\/careerfoundry.inbearbeitung.de\/en\/blog\/web-development\/engineer-vs-developer\/\">What\u2019s the Difference Between a Software Engineer and a Web Developer?<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>If you want to learn JavaScript development, you&#8217;ll need to use React. Learn in this guide what is React.js, how to use it, and why it&#8217;s so great.<\/p>\n","protected":false},"author":134,"featured_media":12057,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_lmt_disableupdate":"yes","_lmt_disable":"","footnotes":""},"categories":[5],"tags":[],"class_list":["post-12050","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development"],"acf":{"homepage_category_featured":false},"modified_by":"Matthew Deery","_links":{"self":[{"href":"https:\/\/careerfoundry.inbearbeitung.de\/en\/wp-json\/wp\/v2\/posts\/12050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerfoundry.inbearbeitung.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerfoundry.inbearbeitung.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerfoundry.inbearbeitung.de\/en\/wp-json\/wp\/v2\/users\/134"}],"replies":[{"embeddable":true,"href":"https:\/\/careerfoundry.inbearbeitung.de\/en\/wp-json\/wp\/v2\/comments?post=12050"}],"version-history":[{"count":3,"href":"https:\/\/careerfoundry.inbearbeitung.de\/en\/wp-json\/wp\/v2\/posts\/12050\/revisions"}],"predecessor-version":[{"id":28573,"href":"https:\/\/careerfoundry.inbearbeitung.de\/en\/wp-json\/wp\/v2\/posts\/12050\/revisions\/28573"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerfoundry.inbearbeitung.de\/en\/wp-json\/wp\/v2\/media\/12057"}],"wp:attachment":[{"href":"https:\/\/careerfoundry.inbearbeitung.de\/en\/wp-json\/wp\/v2\/media?parent=12050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerfoundry.inbearbeitung.de\/en\/wp-json\/wp\/v2\/categories?post=12050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerfoundry.inbearbeitung.de\/en\/wp-json\/wp\/v2\/tags?post=12050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}