<?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"><channel><title><![CDATA[React101]]></title><description><![CDATA[React101]]></description><link>https://react101.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 03:13:46 GMT</lastBuildDate><atom:link href="https://react101.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA["A country of Geniuses in a Data center" What does this phrase mean??]]></title><description><![CDATA[One of the most striking phrases in Dario Amodei’s essay The Adolescence of Technology is his description of advanced AI as “a country of geniuses in a datacenter.” It’s vivid, rhetorically effective,]]></description><link>https://react101.hashnode.dev/a-country-of-geniuses-in-a-data-center-what-does-this-phrase-mean</link><guid isPermaLink="true">https://react101.hashnode.dev/a-country-of-geniuses-in-a-data-center-what-does-this-phrase-mean</guid><dc:creator><![CDATA[Abdikhafar Issack]]></dc:creator><pubDate>Wed, 25 Feb 2026 21:38:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/66f820e854a3a0cc14c4d0ff/90ea3d34-828b-4c4a-ba0e-3b93a31774bc.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>One of the most striking phrases in <strong>Dario</strong> <strong>Amodei’s</strong> essay The Adolescence of Technology is his description of advanced AI as “a country of geniuses in a datacenter.” It’s vivid, rhetorically effective, and alarming. If taken at face value, it suggests that we are on the brink of creating something like a nation-state of minds with each one as capable as humanity’s best thinkers, operating at machine speed and scale.</p>
<p>What do we mean by “genius”?</p>
<p>If “genius” means excelling at the kinds of tasks our education system rewards—fast recall, pattern recognition, test-taking, and the regurgitation of existing facts—then yes, modern AI already looks impressive, and future systems will look staggering.</p>
<p>But if “genius” means something closer to what actually drives discovery in hard fields—biotechnology, physics, chemistry, medicine—the picture becomes much more complicated.</p>
<p>Can AI Be “As Good as Humans at Almost Everything” in 3–5 Years?</p>
<p>Amodei suggests that AI may soon be better than humans at essentially everything. Whether or not one accepts the timeline, the claim collapses under closer inspection of what “everything” entails.</p>
<p>Amodei appears to define “everything” as answering basic questions, writing code, summarizing literature, and optimizing known objectives.  Under this criteria, then yes, AI may surpass most humans in many areas.</p>
<p>Under a more realistic definition of “everything” includes, for example, original discovery, deep expertise in adversarial or uncertain environments, leadership under ambiguity, ethical judgment in novel situations, and redefining problems rather than solving predefined ones, Amodei’s claim is far less convincing.</p>
]]></content:encoded></item><item><title><![CDATA[Let`s Build Robust Web Application With React]]></title><description><![CDATA[Introduction
ReactJS or React is one of the most popular JavaScript(JS) libraries as of 2023, used for building dynamic user interfaces. It has over 200K stars on GitHub and over 40% of professional developers say they use it extensively. It has gain...]]></description><link>https://react101.hashnode.dev/lets-build-robust-web-applications-with-react</link><guid isPermaLink="true">https://react101.hashnode.dev/lets-build-robust-web-applications-with-react</guid><category><![CDATA[React]]></category><category><![CDATA[React Native]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Abdikhafar Issack]]></dc:creator><pubDate>Thu, 10 Oct 2024 19:52:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1728590658703/630d4b3b-292c-49f3-97dc-801cb5d9c749.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction"><strong>Introduction</strong></h2>
<p><a target="_blank" href="https://react.dev/"><strong>ReactJS or React</strong></a> is one of the <strong>most popular JavaScript(JS) libraries</strong> as of 2023, used for building dynamic user interfaces. It has <strong>over 200K</strong> stars <a target="_blank" href="https://github.com/facebook/react"><strong>on GitHub</strong></a> and <strong>over 40%</strong> of professional developers say they use it extensively. It has gained widespread adoption due to its <strong>simplicity, flexibility, and performance</strong>.</p>
<p>React is easier to learn and grasp the fundamentals than any other <strong>JS library/framework</strong> like Angular since its syntax and structure are very similar to plain JavaScript by use of an extension known as <a target="_blank" href="https://en.wikipedia.org/wiki/JSX_\(JavaScript\)"><strong>JSX</strong></a>. Every JavaScript concept can apply to your React application hence you can therefore build your first web application with React in very little time.</p>
<p><em>But wait, before we dive straight into how to work with React, we need to build a little bit of context.</em></p>
<h3 id="heading-react-history">React History</h3>
<p><em>Using</em> <a target="_blank" href="https://en.wikipedia.org/wiki/React_\(JavaScript_library\)"><strong><em>Wikipedia</em></strong></a>, <em><mark>React was created by Jordan Walke, a Software Engineer at Meta, formerly Facebook, who released an early prototype of React called "FaxJS". He was influenced by </mark></em> <a target="_blank" href="https://en.wikipedia.org/wiki/XHP"><strong><em><mark>XHP</mark></em></strong></a><em><mark>, an </mark></em> <a target="_blank" href="https://en.wikipedia.org/wiki/HTML"><strong><em><mark>HTML</mark></em></strong></a> <em><mark>component library for </mark></em> <a target="_blank" href="https://en.wikipedia.org/wiki/PHP"><strong><em><mark>PHP</mark></em></strong></a><em><mark>. It was first deployed on Facebook's News Feed in 2011 and later on Instagram in 2012 then later open-sourced at JSConf US in May 2013, the Initial Public Release.</mark></em></p>
<p>Since its initial release, React has gained popularity randomly and continued to grow ever since, revolutionizing the world of Web Development. In present days, it is being used by some of the biggest names in the tech industry, including Pinterest, Meta, Instagram, Netflix, Shopify, Discord, Dropbox and many more.</p>
<p><a target="_blank" href="https://trends.google.com/trends/explore?date=all&amp;q=%2Fm%2F012l1vxv"><strong><em>ReactJS Google Trends from 2004 - Present</em></strong></a></p>
<p><a target="_blank" href="https://trends.google.com/trends/explore?date=all&amp;q=%2Fm%2F012l1vxv"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678255538626/0fe84202-4ac9-40b8-94b7-b7288542ef6d.png?auto=compress,format&amp;format=webp" alt="ReactJS Google Trends from 2004 to Present" /></a></p>
<hr />
<p>Traditionally, the front-end landscape was very different. We just had basic HTML, CSS and JavaScript where HTML displayed the text on the Web page, CSS the styles and JavaScript allowed us to have some interactivity in a website. Additionally, when a user clicked a URL, we used to request these three files from the server <em>(or backend)</em> but there was a problem with that. Different browsers were being used to run the websites and developers had to account for all the different browsers as much as they wanted to use more and more JavaScript. This is because each browser had been built by different developers.</p>
<p><a target="_blank" href="https://web.archive.org/web/20000407052548/http://www.amazon.com/exec/obidos/subst/home/home.html"><strong><em><mark>Amazon site in April 2000</mark></em></strong></a><em><mark>:</mark></em></p>
<p><a target="_blank" href="https://web.archive.org/web/20000407052548/http://www.amazon.com/exec/obidos/subst/home/home.html"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682799882054/fbed88f1-bee9-4dc9-a4f1-04b0c9816458.png?auto=compress,format&amp;format=webp" alt="Amazon.com in April 2000 Image" /></a></p>
<p>Eventually, <a target="_blank" href="https://jquery.com/"><strong>jQuery</strong></a> came out, which allowed developers to easily interact with the <a target="_blank" href="https://en.wikipedia.org/wiki/Document_Object_Model"><strong>DOM</strong></a> across all browsers. It had a unified, easy API that took care of all the complexity of manipulating the front end across different browsers. Developers started building bigger and bigger applications and as websites started turning into full applications, <a target="_blank" href="https://backbonejs.org/"><strong>BackboneJS</strong></a> was 'born' which was also a library that allowed us to organize JavaScript files. As it became easier and easier to work with the DOM, we had the birth of <a target="_blank" href="https://geekflare.com/single-page-applications/"><strong>single-page applications</strong></a>.</p>
<p>Developers focused less on HTML and more on JavaScript where instead of us making new requests to the server after each click, one would interact with that application without ever speaking to the server anymore, and in 2013, <a target="_blank" href="https://about.meta.com/"><strong>Meta</strong></a> (formerly Facebook) released ReactJS at <a target="_blank" href="https://jsconf.com/"><strong>JSConf</strong></a> which became the most popular tool with the most job demand across the world.</p>
<h3 id="heading-growth">Growth</h3>
<p>Since its release, React JS has had a thriving community of passionate developers who are constantly pushing the boundaries of what's possible with this powerful technology.</p>
<p>From innovative tools and libraries to cutting-edge tutorials and support forums, there is an abundance of resources available for anyone who wants to learn and master React JS. Therefore, not only will you have access to one of the most exciting and innovative technologies out there, but you'll also have a wealth of support and inspiration to help you take your skills to the next level.</p>
<p><em><mark>As I will be wrapping up this article-series, I will mention a few of the best resources to help you kick-start your journey in learning React JS and have a clear path to success in taking your web development skills to the next level.</mark></em></p>
<p><em>But how much JavaScript do I need to get started in React?</em></p>
<p>To have a good grasp and an easier path in learning React, you just need to have basic JavaScript skills at your fingertips. This includes knowledge of how to work with:</p>
<ul>
<li><p>Data types</p>
</li>
<li><p>Variables</p>
</li>
<li><p>Basic Operators</p>
</li>
<li><p>Logic Operators</p>
</li>
<li><p>Functions</p>
</li>
<li><p>Objects</p>
</li>
<li><p>Loops</p>
</li>
<li><p>DOM Manipulation</p>
</li>
<li><p>Arrays</p>
</li>
<li><p>ES6 <em>Modern</em> Syntax</p>
</li>
<li><p>Object Oriented Programming</p>
</li>
<li><p>Asynchronous JavaScript</p>
</li>
<li><p>and Modern JS Development <em>(Modules, and Tooling)</em></p>
</li>
</ul>
<p>To learn the above JavaScript skills, I would highly advocate for the <a target="_blank" href="https://www.udemy.com/course/the-complete-javascript-course/"><strong>Complete JavaScript Course 2023: From Zero to Expert! by Jonas Schmedtmann</strong></a> on Udemy <em>which is a paid course</em>, or use <em>(one of the full-course-tutorials)</em> in the free <a target="_blank" href="https://youtube.com/playlist?list=PLWKjhJtqVAbleDe3_ZA8h3AO2rXar-q2V"><strong>JavaScript Tutorials Playlist by freeCodeCamp</strong></a> on YouTube.</p>
<hr />
<p><em>What made React so great and Why React instead of 'Just JavaScript'</em> <em>(</em><a target="_blank" href="https://www.javatpoint.com/what-is-vanilla-javascript"><strong><em>Vanilla JS</em></strong></a><em>)?</em></p>
<p><a target="_blank" href="https://www.javatpoint.com/what-is-vanilla-javascript"><strong>Vanilla JS</strong></a> is used to refer to pure JavaScript <em>(or we can say plain JavaScript)</em> without any type of additional library. Vanilla JS works and is at times a good choice but the downside is that it can also reach its limits. One of the reasons is that using vanilla JS, you have to write every single step that should be taken as you design a program; Every single step has to be described. This way of programming is called an <a target="_blank" href="https://www.techtarget.com/whatis/definition/imperative-programming#:~:text=Imperative%20programming%20is%20a%20software,models%20are%20not%20called%20on."><strong>imperative approach</strong></a>; Describing action after action, and step after step.</p>
<p>In programming and Software Development in general, we have a principle aimed at reducing the repetition of software patterns, replacing it with abstractions or using data normalization to avoid redundancy referred to as <strong>DRY</strong> <em>(Don't Repeat Yourself)</em>. However, using the Vanilla JS imperative approach, we end up reinventing the wheel over and over again; Doing repetitive tasks by repeating code that does the same task over and over again.</p>
<p>React on the other hand makes use of <a target="_blank" href="https://reactjs.org/docs/components-and-props.html"><strong>Components</strong></a>, which are independent and reusable bits of code. They serve the same purpose as JavaScript functions, but work in isolation and return HTML. React is therefore about splitting your application into small building blocks <em>(small components)</em>, where every building block <em>(every component)</em> has its specific task and can be reused in the program making your code maintainable and manageable. ReactJS, therefore, makes building modern, rich, complex user interfaces way easier by giving us a <em>higher-level syntax</em> where we write code in a <a target="_blank" href="https://www.techtarget.com/searchitoperations/definition/declarative-programming#:~:text=Declarative%20programming%20is%20a%20method,the%20opposite%20of%20imperative%20programming."><strong>Declarative, <em>component-focused</em> approach</strong></a>.</p>
<hr />
<h3 id="heading-react-components">React Components</h3>
<p>React is designed around the concept of reusable components which was a big game changer.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682857695373/7faa958e-937a-4849-8270-634628f3dc6c.jpeg?auto=compress,format&amp;format=webp" alt /></p>
<p>Using the image above of the Facebook website <em>(some years ago)</em>, each square or rectangle section is an individual component where after bringing all the components together, we get the complete website as a whole. A component is a self-contained piece of code that returns some virtual UI representation of HTML. This borrows the concept of <a target="_blank" href="https://entertainment.howstuffworks.com/lego.htm"><strong>working with Lego blocks</strong></a>. <em>Example</em>, we have the <em>Navigation Bar component</em> and the <em>News Feed component</em> in the image. We can also have components within components where a component like a <em>Profile Picture component</em> or <em>Button component</em> can be surrounded by a bigger component like the <em>News Feed component</em>. Each of these components works together to eventually have our whole working web app. The advantage of having these components, as mentioned before, is that they can be reused in different locations in the project.</p>
<p><em><mark>We'll however dive deeper into components later in the article-series.</mark></em></p>
<h3 id="heading-data-flow-in-react">Data Flow in React</h3>
<p>So far, we understand that React is just a JavaScript library that allows us to write more JavaScript to have interactivity on our websites. In React, data flow refers to how data is passed between components. React employs a <strong>one-way data flow</strong> or <strong>unidirectional data flow</strong>. It is sometimes referred to as the <strong>one-way data binding model</strong>.</p>
<p>In a unidirectional data flow, as the name goes, data flows in a single direction, which is from a parent component down to its child components. <em>Example</em>, we can have a <em>Button component</em> inside a <em>News Feed component</em>. The <em>News Feed component</em> is the parent component while the <em>Button component</em> is the child component, hence data can be passed from the <em>News Feed component</em> to the <em>Button component</em>. This means that data changes made in a child component cannot directly affect the data in its parent or sibling components.</p>
<p>In React, this is achieved by passing data down through <strong>props</strong> <em>(which we'll discuss and put into practice later)</em>. <strong>Props</strong> are essential properties that can be passed down from a parent component to its child components. Once a child component receives props from its parent, it can use those props to render itself. In our example above, the <em>News Feed component</em> can pass data down to the <em>Button component</em> through props.</p>
<p><em>If the child component needs to modify the data it has received from its parent, it can do so by raising an event but we'll also discuss how this happens later.</em></p>
<p>This <strong>unidirectional flow</strong> of data helps to keep the application's data model simple and also makes it easier to debug the application, as changes to data can be easily traced back to their source.</p>
<hr />
<p>Now because things get easier with React, and because we can build those rich user interfaces with React and JavaScript, when working with React we often build so-called <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Glossary/SPA"><strong>Single Page Applications</strong></a> as mentioned in the 'React History' section above. This means controlling the entire page with React, hence when a link is clicked and a new page is loaded, it looks as if one switched a page, but instead, one does not request a new HTML file from some server.</p>
<p>Instead, JavaScript is used through React to change what's visible on the screen where after the initial request, React takes over and controls what we see on the screen, which often leads to <strong>a smoother UI and a better user experience</strong>.</p>
<hr />
<p>As we wrap up the <strong>Introduction</strong> section, it is worth noting that ReactJS has alternatives.</p>
<p><a target="_blank" href="https://www.mindinventory.com/blog/popular-javascript-frameworks-for-frontend-development/"><img src="https://www.mindinventory.com/blog/wp-content/uploads/2022/10/JavaScript-Frameworks1200.jpg" alt="Most Popular Front-end JavaScript Frameworks" /></a></p>
<p>The alternatives include <a target="_blank" href="https://angular.io/"><strong>Angular</strong></a>, <a target="_blank" href="https://vuejs.org/"><strong>VueJS</strong></a>, <a target="_blank" href="https://svelte.dev/"><strong>Svelte</strong></a>, and <a target="_blank" href="https://www.simform.com/blog/javascript-frontend-frameworks/"><strong>many more</strong></a>. Each alternative however has an advantage and a disadvantage over the other and it is advisable to learn and master one first before getting to the next one <em>(if need be)</em>, instead of learning any 2 or more simultaneously.</p>
<hr />
<h2 id="heading-fundamentals">Fundamentals</h2>
<h3 id="heading-create-react-apphttpscreate-react-appdev"><a target="_blank" href="https://create-react-app.dev/"><strong>create-react-app</strong></a></h3>
<p><em>Yes, you saw that right,</em> <strong><em>CRA</em></strong> <em>haha...</em> If you are a newbie in React, you might wonder why I have that statement in the first place. Let us first understand what <strong>create-react-app</strong> is then break everything down as to why we possibly no longer need/use <strong>CRA</strong> but rather its alternative <a target="_blank" href="https://vitejs.dev/"><strong>Vite</strong></a>.</p>
<p><em>What is</em> <a target="_blank" href="https://create-react-app.dev/"><strong><em>create-react-app (CRA)</em></strong></a><em>?</em></p>
<ul>
<li><p>CRA is an officially supported way to create <strong>single-page</strong> <strong>React applications</strong>. It offers a modern build setup with no configuration.</p>
</li>
<li><p>It is a tool that generates a new React site for us along with all of the configuration and dependencies it needs to run. This means it does all the heavy lifting for us when creating a new React App.</p>
</li>
</ul>
<p>To better understand CRA, let's first see it in action. <a target="_blank" href="https://create-react-app.dev/docs/getting-started"><strong>Steps on how to run your first React app with CRA</strong></a>:</p>
<ol>
<li><p>The first step before using CRA is to have <strong>Node &gt;= 14</strong> installed on your machine.</p>
<p> This is because while using CRA, we use the <strong>node package manager (npm)</strong>, to run and build our app.</p>
<p> <a target="_blank" href="https://en.wikipedia.org/wiki/Package_manager"><strong><em>Package Managers</em></strong></a> <em>are tools that enable the automatic installation, configuration, and deletion of software modules, or packages.</em></p>
<p> To install Node, go to the <a target="_blank" href="https://nodejs.org/en/download"><strong>official NodeJS site</strong></a> and download an installer as per your operating system and follow the step-by-step installation process after the installer download.</p>
<p> After installing Node, open the terminal and run <code>node -v</code> and if Node is successfully installed, it should display the Node version installed on your machine. <em>Example</em> : <code>v18.15.0</code></p>
</li>
<li><p>After Node is successfully installed on your machine, run the following CRA command in the terminal: <code>npx create-react-app my-app</code></p>
<p> In the code above, <code>npx</code> is an npm package runner but has <a target="_blank" href="https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b"><strong>added advantages over using npm</strong></a>. It is a part of the node package system, which temporarily downloads a node package for us and then runs it without explicitly installing it. <code>create-react-app</code> is the command that generates our first React App then <code>my-app</code> is the name of your React App or project <em>(You can use any other different name)</em>.</p>
</li>
<li><p>After <code>my-app</code> project is generated, while still in the terminal, type the following command <code>cd my-app</code> <em>(which means we 'change directory' and get into our app's</em> <code>my-app</code> <em>directory)</em> then type <code>npm start</code> which will start the development server <em>(the starting script can be found in the</em> <code>package.json</code> <em>file - file explained below in the 'structure walkthrough' section)</em>.</p>
<p> Then open <a target="_blank" href="http://localhost:3000/"><strong>http://localhost:3000/</strong></a> to see your app <em>(Works only after the above process is completed successfully as shown below)</em>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1681471413993/341cdecd-52b2-417b-af36-396405437398.gif?auto=format,compress&amp;gif-q=60&amp;format=webm" alt /></p>
<p> After opening the app in the local host using a browser of your choice: <a target="_blank" href="http://localhost:3000/"><strong>http://localhost:3000/</strong></a>, the page will look like the one below:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1681471571312/19ebe55c-224e-4e6f-a29e-8cdc68365498.png?auto=compress,format&amp;format=webp" alt /></p>
<p> <em>Ta-daa</em>, you have your first React App running on your local machine. Let us now open the app <em>(</em><code>my-app</code><em>)</em> in any text editor or IDE of your choice <em>(I prefer</em> <a target="_blank" href="https://code.visualstudio.com/"><strong><em>Visual Studio Code - VS Code</em></strong></a><em>).</em></p>
</li>
</ol>
<p>In VS Code <em>(or in any text editor or IDE of your choice)</em>, the folder structure of the app will appear as in the image below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1681472911992/319ab4c4-ef0a-4c1f-b43d-2a111134e474.jpeg?auto=compress,format&amp;format=webp" alt /></p>
<h3 id="heading-structure-walkthrough">Structure Walkthrough</h3>
<ul>
<li><p><strong>node_modules</strong></p>
<p>  The first directory is the <strong>node_modules</strong> directory. This is a directory that stores all of our project dependencies and node packages.</p>
<p>  The React library itself is a node package, and it's kept inside this directory which includes any other packages that one will install in the future will also be stored in this <strong>node_modules</strong> directory.</p>
</li>
<li><p><strong>public</strong></p>
<p>  Next, we have the <strong>public</strong> directory. This directory contains static assets or files and will be made public to the browser, such as the HTML file(s), icon(s), images, and fonts. When you run <code>npm start</code>, this directory is served as the root directory of your app. Examples of files include the <code>favicon.co</code> which is the icon shown in the browser tab, the <code>robot.txt</code> file which is for communicating with search engine crawlers and web scrapers, the <code>manifest.json</code> file which contains a bunch of information about our project and is primarily used when a user wants to install a <a target="_blank" href="https://en.wikipedia.org/wiki/Progressive_web_app"><strong>progressive web app</strong></a>. We also have a HTML file, <code>index.html</code>, which is the single file served to the browser when the app is loaded; where our React application will be injected into the page <em>(more explanation below in the course of the article)</em>.</p>
</li>
<li><p><strong>src</strong></p>
<p>  The <strong>src</strong> directory is the directory that contains the source code for the React application. This is the directory where we build components. When our app is compiled, it's all the files in the src directory that get compiled into a <a target="_blank" href="https://stackoverflow.com/questions/42727269/what-is-an-asset-and-what-is-a-bundle"><strong>JavaScript bundle</strong></a>.</p>
<p>  In the src directory, we have different files as well:</p>
<ul>
<li><p><code>App.js</code> file - This is the main component that is rendered to the DOM when your app is loaded. It contains the logic and structure of your app.</p>
</li>
<li><p><code>App.css</code> file - This is a file used to style the components in the app.</p>
</li>
<li><p><code>index.css</code> file - This is the global stylesheet where styling is done globally in the entire app.</p>
</li>
<li><p><code>logo.svg</code> file - This is an image in the form of an <a target="_blank" href="https://en.wikipedia.org/wiki/SVG"><strong>SVG</strong></a> being used in the App component.</p>
</li>
<li><p><code>index.js</code> file - This is the file that kinda kickstarts the React application. It is the entry point of any React application as it imports <code>App.js</code> and renders it to the root element in <code>index.html</code>.</p>
</li>
<li><p><code>App.test.js</code> file - Used for writing tests for the App component.</p>
</li>
<li><p><code>setupTests.js</code> file - Needed for the test files to work by importing a testing library.</p>
</li>
<li><p><code>reportWebVitals.js</code> file - This allows us to measure the performance of the React application by analyzing certain metrics.</p>
<p>  <em>(For the start or as a beginner, one does not work with the</em> <code>App.test.js</code><em>,</em> <code>setupTests.js</code> <em>and</em> <code>reportWebVitals.js</code> <em>files, which are used at a more advanced level, hence one can</em> <strong><em>delete the files and also delete their import statements</em></strong> <em>in the</em> <code>App.js</code> <em>and</em> <code>index.js</code> <em>files.)</em></p>
</li>
</ul>
</li>
<li><p>Additionally, we have more files in the root of our directory:</p>
<ul>
<li><p><code>.gitignore</code> file for version control which tells Git which files or directories to ignore and not track <em>eg the node_module directory</em>.</p>
</li>
<li><p><code>package.json</code> file - This is a file that tells any developer working with the application the different libraries or packages that the project needs in order to work. In other words, it is used for tracking dependencies or packages and their versions for each specific project created with CRA. It contains information about the project, including its dependencies that are stored in the node_modules directory, scripts like building, testing, or deploying your app, and other metadata.</p>
</li>
<li><p><code>README.md</code> file - This is the file used to describe what the app does, how to install it, how to use it, and any other relevant information.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-vitehttpsvitejsdev-gt-cra"><a target="_blank" href="https://vitejs.dev/"><strong>Vite</strong></a> <strong>&gt; CRA</strong></h3>
<p><strong>What is</strong> <a target="_blank" href="https://vitejs.dev/"><strong>Vite</strong></a><strong>?</strong> Vite, like <a target="_blank" href="https://create-react-app.dev/"><strong>CRA</strong></a><strong>,</strong> is a build tool that is designed to be fast and optimized for modern web development workflows. It too generates a new React site for us along with all of the configuration and dependencies it needs to run hence doing all the heavy lifting for us as well.</p>
<p>Vite works like CRA but <a target="_blank" href="https://vitejs.dev/guide/why.html"><strong>has added advantages</strong></a>:</p>
<ol>
<li><p><strong>Speed</strong> - Vite is blazingly fast as compared to CRA. This is because it uses a new generation of build tooling that leverages modern JavaScript features hence significantly reducing the time it takes to build and reload your app during development, as compared to CRA which uses a more traditional build process that is slower, especially for larger applications.</p>
</li>
<li><p><strong>Flexibility</strong> - You can easily tailor it to your specific needs as it was designed to be highly configurable and customizable.</p>
</li>
<li><p><strong>Performance</strong> - Vite has a smaller build output than CRA hence improving the performance, and loading time of your web application.</p>
</li>
</ol>
<p><em>But how do we create our first react app with Vite?</em></p>
<p>For CRA, we saw that we use the command: <code>npx create-react-app my-app</code> to generate a new React app.</p>
<p>For Vite, we use: <code>pnpm create vite@latest</code>. Before we expound more on the command(s), I've just introduced another tool here. We have seen <code>npm</code> and <code>npx</code> before, but now we have <a target="_blank" href="https://pnpm.io/"><strong>pnpm</strong></a>. <code>pnpm</code> is also a package manager but faster than <code>npm</code>. You can learn more about <code>pnpm</code> in the <a target="_blank" href="https://pnpm.io/"><strong>pnpm official documentation</strong></a>; how to install it and why it is preferred over npm. However, you can still use npm: <code>npm create vite@latest</code>.</p>
<p>After you run <code>pnpm create vite@latest</code> in the terminal, you are prompted to add the <strong>Project name</strong>, the default being <em>vite-project</em>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1683248298407/8b1051d8-dfd7-41e5-ba31-17d064631a38.png?auto=compress,format&amp;format=webp" alt /></p>
<p>We are still gonna use our project name as <code>my-app</code> then click <strong><em>Enter</em></strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1683248370747/23584b74-6ba8-4608-8d72-ca61cd65fc0a.png?auto=compress,format&amp;format=webp" alt /></p>
<p>After adding the project name, we are prompted to select the framework we are to use in our project. Vite supports several libraries \ frameworks as shown in the image above but because we are using React, we will select 'React'.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1683248574209/e2bf1edb-397b-4509-8b1b-8e05ada55a43.png?auto=compress,format&amp;format=webp" alt /></p>
<p>After selecting 'React', we are to select whether we are to use React with <a target="_blank" href="https://www.typescriptlang.org/docs/handbook/react.html"><strong>TypeScript</strong></a> or <a target="_blank" href="https://react.dev/learn"><strong>JavaScript</strong></a>. We are to select JavaScript for this project. However, we have two options for both JavaScript and TypeScript; we have one with <strong>JavaScript</strong> and the second option with <strong>JavaScript + SWC</strong>. <a target="_blank" href="https://swc.rs/"><strong>SWC</strong></a> is a <a target="_blank" href="https://devopedia.org/transpiler"><strong>transpiler</strong></a> for JavaScript / TypeScript that is written in <strong>Rust</strong> and is much faster than <a target="_blank" href="https://babeljs.io/"><strong>Babel</strong></a> <em>(JavaScript option with no '<em>**</em>\</em>*+ SWC'<strong><em> </em>uses Babel)*, used for both compilation and bundling. </strong>Rust<strong> is known for its performance and reliability, hence for compilation, </strong>SWC<strong> takes JavaScript / TypeScript files using modern JavaScript features and outputs valid code that is supported by all major browsers [</strong>20x faster than Babel**](https://swc.rs/#:~:text=20x%20faster%20than%20Babel). It speeds up the development, production builds and outputs smaller files hence much faster than Babel.</p>
<p><em>You can check the article:</em> <a target="_blank" href="https://blog.logrocket.com/why-you-should-use-swc/"><strong><em>Why you should use SWC (and not Babel)</em></strong></a> <em>by Kasra Khosravi for more information on the differences and advantages of SWC over Babel.</em></p>
<p>After selecting <strong>JavaScript + SWC</strong>, our app (<code>my-app</code>) is generated.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1683249915075/7ab9a696-ec77-44d2-b376-a08e88b07151.png?auto=compress,format&amp;format=webp" alt /></p>
<p>The same process we used as we were working with CRA, we'll <em>'change directory'</em> <code>cd my-app</code> to get into our projects directory. Secondly, we're to install our projects dependencies with <code>pnpm install</code> or <code>npm install</code> <em>(depending on the package manager you initially preferred to use).</em> Then to run our project, with CRA we were using <code>npm start</code> but for Vite, we are to use <code>pnpm run dev</code> or <code>pnpm dev</code> <em>(the starting script can be found in the</em> <code>package.json</code> <em>file - file explained above in the 'structure walkthrough' section)</em></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1683250980020/d366cf5a-3789-4105-b27a-7fc4bda4577e.gif?auto=format,compress&amp;gif-q=60&amp;format=webm" alt /></p>
<p>After running <code>pnpm run dev</code> or <code>pnpm dev</code> the development server for our application (<code>my-app</code>) is typically started and we can open our web app on our local machine, the same way we did in CRA, but this time, vite provides a different <a target="_blank" href="https://en.wikipedia.org/wiki/Localhost"><strong>local host</strong></a> port. <em>eg:</em> <a target="_blank" href="http://localhost:5173/"><strong><em>localhost:5173</em></strong></a>.</p>
<p>Opening our project in VS Code <em>(or in any text editor or IDE of your choice)</em>, the folder structure of the app will appear as in the image below which is almost similar to the CRA folder structure:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1683251940937/b48a29ae-0a22-4932-aefe-5fc076f150a3.png?auto=compress,format&amp;format=webp" alt /></p>
<p>However, in Vite's folder structure, some files <em>(which are not so-used files but can be added manually if need be)</em> like the test files are not generated. Secondly, in CRA, JavaScript files have a <code>.js</code> file extension while using Vite, files have a <code>.jsx</code> extension, <em>a JavaScript extension we'll cover soon</em>. Additionally, the entry point of any React application built with Vite is the <code>main.jsx</code> file which works the same as the <code>index.js</code> file in CRA.</p>
<hr />
<h2 id="heading-react-basics">React Basics</h2>
<p>We've covered how we can create our first react app with both <strong>CRA</strong> and <strong>Vite</strong>. Let's now get deeper into working with React. Create your React app: <em>(I highly advocate using Vite as explained above):</em> <code>pnpm create vite@latest</code>, give the project your preferred name and open it in your preferred IDE or Text Editor.</p>
<p><em>For my case in this article, I'll be using</em> <strong><em>Visual Studio Code as my Text Editor</em></strong> <em>and</em> <code>my-app</code> <em>as my project's name.</em></p>
<p><strong>Point to Note</strong>: <mark>Besides using your Text Editor and local machine to work with React, there's also an option of using your browser </mark> <em><mark>(online)</mark></em> <mark>on a platform known as </mark> <a target="_blank" href="https://codesandbox.io/s/react-new"><strong><mark>Codesandbox</mark></strong></a> <mark>to work with React but on an online Sandbox.</mark> This is an awesome platform to even test your React code for smaller projects.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1683283447424/582c8a97-3d46-4ad2-8a51-e92ae8673a34.png?auto=compress,format&amp;format=webp" alt /></p>
<p>Before getting into basics, did I mention the <a target="_blank" href="https://react.dev/learn"><strong>React Documentation</strong></a>? <em>No, I didn't</em>... The <a target="_blank" href="https://react.dev/learn"><strong>React Documentation</strong></a> is an incredibly comprehensive and well-written resource that covers everything from the basics of React syntax, and installation to advanced topics like <a target="_blank" href="https://react.dev/reference/react"><strong>working with built-in React Hooks and APIs</strong></a>. I highly advocate this unparalleled resource for learning and diving deeper into React.</p>
<p><em>Buckle up and let's kick off!!</em></p>
<hr />
<p>After creating your project and opening it in your preferred browser, let's head over to the <code>index.js</code> file for those using CRA or <code>main.jsx</code> file for those using Vite:</p>
<p><em>(I'm using Vite and below is the code in the</em> <code>main.jsx</code> <em>file)</em></p>
<p><strong>Copy</strong></p>
<p><strong>Copy</strong></p>
<pre><code class="lang-plaintext">import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')).render(
  &lt;React.StrictMode&gt;
    &lt;App /&gt;
  &lt;/React.StrictMode&gt;,
)
</code></pre>
<p>Let's break the above code down so that we can understand why we refer to this file as the entry point of our application.</p>
<p>After starting our development server, <code>pnpm run dev</code>, what happens under the hood is that, first, the <code>main.jsx</code> file imports a couple of libraries, which include the main ones which are <strong>React</strong> and <strong>ReactDOM.</strong> Both of these libraries are very critical in order for our React application to run. React is kinda the underlying engine that does all of the work when it comes to how React functions as an application builder. Anytime we write JSX code <em>(as we will cover in a few)</em> like <code>&lt;MyComponent /&gt;</code> or <code>&lt;App /&gt;</code>, this JSX code is transpiled to a call to <code>React.createElement(MyComponent)</code> or <code>React.createElement(App)</code>, respectively. Hence, in order to have access to the React object in our code, we need to import it: <code>import React from 'react'</code>. <em>The</em> <code>React.createElement()</code> <em>function allows us to use JSX syntax and have it transpiled to executable JavaScript code that the browser can understand.</em></p>
<p>Secondly, <strong>ReactDOM</strong> is related to the <a target="_blank" href="https://en.wikipedia.org/wiki/Document_Object_Model"><strong>DOM</strong></a> we've been mentioning previously, which is the Web DOM. Being that React is the engine that runs how these applications get built, React Dom is specifying that the engine should be directed toward web-related applications. These two libraries combined is what allows us to build out all of our web application in React. You might be wondering, <em>well, are there other React-related libraries for building out other things?</em> Yeah sure, we have <a target="_blank" href="https://reactnative.dev/"><strong>React Native</strong></a> which is for building native mobile applications using React as well as the underlying engine and also a virtual reality application tool, <a target="_blank" href="https://developer.oculus.com/blog/building-virtual-reality-experiences-on-the-web-with-react-vr/"><strong>React VR</strong></a>, that you can build, also leveraging the React engine. So that's why for our web application, we want both React and ReactDOM.</p>
<p><strong><mark>We no longer need to import React and ReactDOM in our JavaScript files anymore.</mark></strong> <em>Wait, what are you saying? You just mentioned that we need to import the React engine and a library to specify that the engine should be directed toward web-related applications</em>. Yes, <strong>We no longer need to import React and ReactDOM in our JavaScript files anymore.</strong> This is because when React 17 was introduced, it has a new JSX transform feature that allows us to use JSX without importing React and ReactDOM. However, if one is using an older version of React, one still needs to import React and ReactDOM. Hence, we can do away with both lines of code in our <code>main.jsx</code> file since we are using the latest version of React:</p>
<p><strong>Copy</strong></p>
<p><strong>Copy</strong></p>
<pre><code class="lang-plaintext">import App from './App.jsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')).render(
  &lt;React.StrictMode&gt;
    &lt;App /&gt;
  &lt;/React.StrictMode&gt;,
)
</code></pre>
<p>We also import the App component from the <code>App.jsx</code> file where the main component, <strong>App component</strong>, is rendered to the DOM when your app is loaded <em>(as explained in the 'structure walkthrough' section)</em>. We also import the <code>index.css</code> file which is the global stylesheet with our styles for our app at a global scope.</p>
<p>Let's now understand how the code below works:</p>
<p><strong>Copy</strong></p>
<p><strong>Copy</strong></p>
<pre><code class="lang-plaintext">ReactDOM.createRoot(document.getElementById('root')).render(
  &lt;React.StrictMode&gt;
    &lt;App /&gt;
  &lt;/React.StrictMode&gt;,
)
</code></pre>
<p>Explanation in a nutshell, <em>"Leveraging the</em> <strong><em>ReactDOM</em></strong> <em>library, we want to render our App component</em> <code>&lt;App /&gt;</code> <em>and mount it in an HTML document element with the ID 'root'."</em> This is happening / the element with the ID of 'root' is in the <code>index.html</code> file which is in the public directory.</p>
<p><strong>Copy</strong></p>
<p><strong>Copy</strong></p>
<pre><code class="lang-plaintext">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8" /&gt;
    &lt;link rel="icon" type="image/svg+xml" href="/vite.svg" /&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt;
    &lt;title&gt;Vite + React&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;

    &lt;div id="root"&gt;&lt;/div&gt; &lt;!-- The HTML element with the root ID --&gt;

    &lt;script type="module" src="/src/main.jsx"&gt;&lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>What is happening is that our entire React application, which we can also refer to as the main <strong>App</strong> component is rendered into the div with the root ID. Hence, while in the browser, all the elements in other components or the main App component will be located in between this div with the 'root' ID.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1683294671804/ab0083a5-5426-434c-bec3-814d462cdab4.png?auto=compress,format&amp;format=webp" alt /></p>
<p>To see this in practice, in case we add a new element below the root div element in our original project, (<code>my-app</code>) and run the development server:</p>
<p><strong>Copy</strong></p>
<p><strong>Copy</strong></p>
<pre><code class="lang-plaintext">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8" /&gt;
    &lt;link rel="icon" type="image/svg+xml" href="/vite.svg" /&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt;
    &lt;title&gt;Vite + React&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;

    &lt;div id="root"&gt;&lt;/div&gt; &lt;!-- The HTML element with the root ID --&gt;
    &lt;h1&gt;React Code outside the root&lt;/h1&gt;
    &lt;script type="module" src="/src/main.jsx"&gt;&lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>In our browser developer tools, we then see that the h1 element was not rendered in between the root element but in the body tag and in its separate h1 tag:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1683295181505/52c01e5d-deb4-46e1-87c0-4fd47c8af0e0.png?auto=compress,format&amp;format=webp" alt /></p>
<p>The <code>&lt;React.StrictMode&gt;</code> is a useful development-only tool for identifying potential problems in a React application, especially during development and testing to identify potential problems in a React application. By wrapping the main App component of our application in <code>React.StrictMode</code>, we can get additional warnings and checks that can help us write more robust and maintainable React code. <strong>It should however be used during development and removed in production builds.</strong> This is because the additional checks and warnings can add some overhead to the application, which can affect its performance.</p>
<h3 id="heading-using-stylesheets">Using Stylesheets</h3>
<p>In our <strong>src</strong> directory, we have <code>index.css</code> and <code>App.css</code> files that we kinda explained above but let's now see how we can work with these files.</p>
<p>The <code>index.css</code> file is the global stylesheet for our entire website that is used to hold basic styles for common elements or classes that are used in many different places in our application. <em>Examples</em> include heading styles, button styles, body styles etc. This <code>index.css</code> file is then imported into the <code>main.jsx</code> file, the file that kick-starts our React application, then it is effectively injected into a style tag on the HTML page in the browser.</p>
<p>The <code>App.css</code> file is a stylesheet for our components, where different components eg, <em>News Feed Component</em> or <em>Navbar Component</em> are styled. Splitting our stylesheets into global and component-specific stylesheets makes it easier to manage our application especially as it starts to get larger and we start adding more and more components. Having one gigantic stylesheet may become messy and hard to update.</p>
<p>However, it's worth noting that even component-specific styles are also kinda treated as global styles and hence are placed in the head of the HTML page as a style tag too so they can apply styles to anything or any component on the page.</p>
<p><strong><em>There's more to styling a React application than just the two options above which we'll dive deeper into later in the article.</em></strong> <em>(For this section, let's focus on the basics of using stylesheets).</em></p>
<h3 id="heading-using-images">Using Images</h3>
<p>Let's now discuss how we use images in our JSX file(s). There are two ways how we can use images in our React application.</p>
<p>Using our <code>my-app</code> project, we can add images to the <strong>public</strong> directory and use them from there. As we mentioned above, anything placed in the public directory will be made public to the browser or is available at the root level of the domain. So if we place an image inside there, then we can just reference it in our image tags without the need of importing the image.</p>
<p><strong>Copy</strong></p>
<p><strong>Copy</strong></p>
<pre><code class="lang-plaintext">&lt;img src="/vite.svg" className="logo" alt="Vite logo" /&gt;
</code></pre>
<p>The second option is using the <strong>src</strong> directory. We can create another directory <em>(however it already exists in our current Vite project)</em> known as <strong>assets</strong> where we can place all our images. This is for easier management of our files in our src directory. Files placed in the src directory have to be imported hence to use our images in our JSX files/components, we have to import them at the top. We then use curly braces to refer to the image files in our image tags since we're outputting something dynamic. In React, when we want to output dynamic content or expressions within our JSX code, we use curly braces { } to enclose the dynamic content.</p>
<p><strong>Copy</strong></p>
<p><strong>Copy</strong></p>
<pre><code class="lang-plaintext">import reactLogo from './assets/react.svg'
&lt;img src={reactLogo} className="logo react" alt="React logo" /&gt;
</code></pre>
<p>But which way is the better way? There's no better method than the other, however, if one is using an image outside the scope of React which means somewhere else on the HTML page outside of the root element where the application is injected, or even when using site-wide images that might be used in many different places, one can use the <strong>public</strong> directory. But for images that are used in specific components, one can use the <strong>src</strong> directory.</p>
<hr />
<p>Before we wrap up the basics section, let's first check out one key tool we ought to know of, which is the <code>pnpm build</code> command. Opening our <code>package.json</code> file, in the scripts section we have the following scripts:</p>
<p><strong>Copy</strong></p>
<p><strong>Copy</strong></p>
<pre><code class="lang-plaintext">"scripts": {
  "dev": "vite",
  "build": "vite build",
  "lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0",
  "preview": "vite preview"
}
</code></pre>
<p>We've worked with the dev, <code>pnpm dev</code>, script. The built script, <code>pnpm build</code>, is the script used to build our project and generate a set of optimized static assets that can be deployed to a web server. After running the <code>pnpm build</code> command in the terminal while in our projects directory, a directory similar to the one below will be generated with optimized files ready for deployment.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1683325462457/2500bed9-27ca-4aec-8aa2-5749b491a00b.png?auto=compress,format&amp;format=webp" alt /></p>
<p>The resulting assets after the build process is complete are ready for deployment and can be served by a web server or a cloud-based service.</p>
<hr />
<h2 id="heading-milestone-wrap">Milestone wrap...</h2>
<p>Aha! We are done with the first milestone of understanding <strong>'What is React and Why React?'</strong> We have also covered some terminologies in React like <strong>React components</strong>, <strong>create-react-app</strong>, <strong>vite</strong>, <strong>scripts</strong> and many more. 🥳</p>
<p>This is just but the start of our learning React series, and we are yet to dive into the juicy bits of React. In the next section, <strong>React 102</strong>, we will dive deeper into working with React components, React hooks, and much, much more...</p>
<p>Are you excited? I am excited 🚀</p>
<p>See you then 🤗</p>
]]></content:encoded></item></channel></rss>