<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Reed - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Reed - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 11 Jun 2026 23:14:29 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/refactor/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ React Libraries to Use in Your Projects in 2024 ]]>
                </title>
                <description>
                    <![CDATA[ If you're building applications with React, you should learn how to use some helpful libraries that'll make it easier to add the features you need. For example, to add features like authentication or styling, you'll need to find a good third-party li... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/react-libraries-to-use-in-your-projects/</link>
                <guid isPermaLink="false">66d037caccf811d3117aeeef</guid>
                
                    <category>
                        <![CDATA[ Libraries ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Fri, 02 Feb 2024 18:42:15 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/02/react-libraries-2024.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you're building applications with React, you should learn how to use some helpful libraries that'll make it easier to add the features you need.</p>
<p>For example, to add features like authentication or styling, you'll need to find a good third-party library to handle it.</p>
<p>In this comprehensive guide, I'm going to show you all of the libraries that I would recommend you use in 2024 to build fast, reliable React apps with ease.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a class="post-section-overview" href="#heading-react-framework">React Framework</a></li>
<li><a class="post-section-overview" href="#heading-package-manager">Package Manager</a></li>
<li><a class="post-section-overview" href="#heading-css-amp-ui-libraries">CSS &amp; UI Libraries</a></li>
<li><a class="post-section-overview" href="#heading-state-management">State Management</a></li>
<li><a class="post-section-overview" href="#heading-data-fetching">Data Fetching</a></li>
<li><a class="post-section-overview" href="#heading-routing">Routing</a></li>
<li><a class="post-section-overview" href="#heading-authentication">Authentication</a></li>
<li><a class="post-section-overview" href="#heading-database-amp-orm">Database &amp; ORM</a></li>
<li><a class="post-section-overview" href="#heading-dates-amp-times">Dates &amp; Times</a></li>
<li><a class="post-section-overview" href="#heading-forms">Forms</a></li>
<li><a class="post-section-overview" href="#heading-drag-amp-drop">Drag &amp; Drop</a></li>
<li><a class="post-section-overview" href="#heading-mobile-apps">Mobile Apps</a></li>
<li><a class="post-section-overview" href="#heading-deployment">Deployment</a></li>
<li><a class="post-section-overview" href="#heading-the-1-library-to-know">TypeScript</a></li>
<li><a class="post-section-overview" href="#heading-become-a-professional-react-developer">Become a Pro React Developer</a></li>
</ul>
<h2 id="heading-react-framework">🛠️ React Framework</h2>
<p>First of all, how do we even create our React app in 2024?</p>
<p>If you want a client-rendered React project, <a target="_blank" href="https://www.freecodecamp.org/news/how-to-create-a-react-app-in-2024/">your best choice is <strong>Vite</strong></a>, which has displaced the deprecated Create React App tool.</p>
<p>If you're interested in building a server-rendered or full-stack React project, <strong>Next.js</strong> is the most complete and popular full-stack React framework. </p>
<p>Next.js version 13 introduced the app router, which gave us features like server components and server actions. These allow us to fetch data and render our React components on the server.</p>
<p>If some of Next.js's features are too complex or you don't understand how to use them, a great full-stack alternative for making dynamic and static sites is <strong><a target="_blank" href="https://remix.run/">Remix</a></strong>.</p>
<p>If you're making an application that you want to load quickly and largely serve static content, another great pick is <strong><a target="_blank" href="https://www.freecodecamp.org/news/learn-the-astro-web-framework/">Astro</a></strong>. Astro allows you to use React alongside other frameworks like Vue and Svelte (meaning it is “framework agnostic”) and is designed to ship the smallest amount of JavaScript necessary to the client, which results in very fast load times.</p>
<h2 id="heading-package-manager">📦 Package Manager</h2>
<p>To install all of these libraries listed in this guide, you're going to need something called a package manager.</p>
<p>If you have Node.js installed, which is necessary to run a React project locally on your computer, you can simply use <strong>NPM</strong>, which is still a great choice in 2024. There are other alternatives to NPM, including Yarn and PNPM.</p>
<p>The newest alternative, which is quickly becoming very popular in the JavaScript world, is <strong><a target="_blank" href="https://www.freecodecamp.org/news/learn-bun-a-faster-node-js-alternative/">Bun</a></strong>. Bun is both a JavaScript runtime like Node as well as a package manager and is marketed as a faster alternative to Node and NPM.</p>
<h2 id="heading-css-amp-ui-libraries">🎨 CSS &amp; UI Libraries</h2>
<p>Now that you've got your project set up and your libraries installed, how are you going to style your React projects?</p>
<p>All of the frameworks I've mentioned above include basic CSS support. It's perfectly fine in 2024 if you want to stick to just styling your React projects with <strong>plain CSS</strong>.</p>
<p>You can use CSS style sheets or CSS modules, but perhaps the most popular choice at the moment in terms of pure styling is to use <strong><a target="_blank" href="https://www.freecodecamp.org/news/learn-tailwind-css/">Tailwind CSS</a></strong>. Tailwind CSS does come with a few setup steps, but it allows you to chain pre-made classes together to quickly add styles directly within your component files.</p>
<p><strong><a target="_blank" href="https://ui.shadcn.com/">ShadCN</a></strong> is a very popular UI library for 2024 that combines Tailwind CSS with a component library called Radix UI. Component libraries like Radix allow you to easily add components without coding them yourself. </p>
<p>ShadCN has become popular due to the greater control it provides over how your components look with the help of Tailwind CSS.</p>
<p>There are a bunch of other very popular functional component libraries as well. <strong>Material UI</strong> still remains popular, as well as others like <strong>Mantine</strong> and <strong>Chakra UI</strong>. Which one you pick really depends on how you want your final app to look. I'd recommend trying out a bunch of these UI libraries and see which one you like best.</p>
<h2 id="heading-state-management">💽 State Management</h2>
<p>React has built-in tools such as <a target="_blank" href="https://www.freecodecamp.org/news/learn-react-usestate-hook-in-10-minutes/">useState</a> and <a target="_blank" href="https://www.freecodecamp.org/news/usereducer-hook-react/">useReducer</a> to manage your app state in basic applications. If you're using Next.js, <a target="_blank" href="https://www.freecodecamp.org/news/how-to-use-urls-for-state-management-in-react/">state management has been moved to the URL</a> when working with server components. Despite these options, you may need a way to manage state in a more precise way.</p>
<p>You might have lots of pieces of state and want greater control over how state updates render your components. If so, you can reach for a dedicated state management library.</p>
<p>Libraries such as <strong>Zustand</strong>, <strong>Recoil</strong>, and <strong>Jotai</strong>, which are all very similar, allow you to manage state simply by declaring properties and methods on an object. This ultimately is the simplest way to handle state management across your app's components.</p>
<p>If I had to pick one state management library for all of my React projects in 2024, I would choose <strong><a target="_blank" href="https://www.npmjs.com/package/zustand">Zustand</a></strong>. It takes almost no time to learn how to use it. It also doesn't require you to add a provider component to your application, which makes it very convenient to use in any component you like.</p>
<h2 id="heading-data-fetching">🐕 Data Fetching</h2>
<p>State management and data fetching often go hand in hand. If you're building a client-rendered React app, you're likely going to need a data fetching library.</p>
<p>The best way to fetch data from a server in a React app in 2024 remains React Query or <strong>Tanstack Query</strong> as it's now called. TanStack Query gives you fine-grained control over not only fetching data, when to fetch and refetch it, caching, all through convenient custom hooks, as well as very easily change or mutate data.</p>
<p>Another solid alternative is <strong>SWR</strong>, which also offers a custom hook to handle queries and mutations, but it's far simpler in terms of what it offers. You can't go wrong with picking either one and fetching data and performing your HTTP requests with the fetch API.</p>
<p><a target="_blank" href="https://www.freecodecamp.org/news/how-to-fetch-api-data-in-react/">Here's an article</a> that walks you through some of the most popular methods of data fetching in React (including Tanstack Query and SWR).</p>
<h2 id="heading-routing">🧭 Routing</h2>
<p>If you're using a framework like Next.js, Remix, or Astro, your routing is already taken care of. All of them come with built-in ways to create routes or pages in your project.</p>
<p>With a client-rendered React app such as one made with Vite or Create React App, you're going to need to pick a routing library. <strong><a target="_blank" href="https://www.freecodecamp.org/news/learn-react-router-6-full-course/">React Router</a></strong> still remains the most popular choice. It takes care of every routing need you might have. It’s also very advanced due to its data loading features with the <code>loader</code> prop. The <code>loader</code> prop allows you to fetch data for a given route without using an external library like React Query.</p>
<p>An up-and-coming library that appears to have equally good features is <strong><a target="_blank" href="https://tanstack.com/router/latest">Tanstack Router</a></strong>. The Tanstack Router was made to be fully type-safe and offer great defaults for data fetching just like React Router version 6 provides.</p>
<p>While Tanstack Router is a bit newer, you really can't go wrong with either choice, and it's a perfect pairing if you're already using Tanstack Query or SWR in your applications.</p>
<h2 id="heading-authentication">🔒 Authentication</h2>
<p>While authentication is something that's handled by the server side of our projects, it's worth knowing what libraries integrate best with React projects, both on the client and the server.</p>
<p>In 2024, <a target="_blank" href="https://www.freecodecamp.org/news/learn-supabase-open-source-firebase-alternative/"><strong>Supabase</strong> has emerged</a> as a very robust authentication solution and offers easy integration with React apps, both on the server, say, in a Next.js project, and on the client. In past years, Firebase was chosen for similar reasons, but it's harder to integrate on the server side of things.</p>
<p>If you're using Next.js, you have a ton of options available to you such as <strong>NextAuth</strong>, <strong>Clerk</strong>, and the newcomer <strong>Lucia</strong>. It's unfortunate that there isn't currently a built-in auth library for Next.js, but perhaps in the future there'll be one.</p>
<p>In the meantime, I'll personally be using Supabase and would highly recommend you check them out as well via their documentation.</p>
<h2 id="heading-database-amp-orm">🥞 Database &amp; ORM</h2>
<p>Much like authentication, your database is something that will and should speak largely to your server-side code.</p>
<p>Databases like Supabase and Firebase don't require that you have a server. You can get and change data directly in the client, and you can add security rules within your dashboard to make sure certain types of requests are allowed or not allowed according to users' authentication status and role.</p>
<p>Outside of these two options, if you're using a traditional server or a full-stack framework, there are countless options. In 2024, the general preference is clearly for SQL databases like MySQL or PostgreSQL over NoSQL databases like MongoDB or Firebase.</p>
<p>With your database, to talk to your database, you'll either use plain SQL or an ORM that allows you to use a custom query language. Popular options for ORMs include <strong>Prisma</strong> or <strong>Drizzle</strong>. Both of them allow you to generate type-safe code so that you know what data will be returned and both integrate very well with SQL or NoSQL databases of your choosing.</p>
<h2 id="heading-dates-amp-times">🕰️ Dates &amp; Times</h2>
<p>When you're working with JavaScript, it's always recommended to have a date library. JavaScript's date constructor is unpredictable and virtually impossible to work reliably with things like time zones.</p>
<p>There are a bunch of options, but I tend to gravitate to <strong>date-fns</strong> or <strong>day.js</strong>. Both are very small but extensive libraries that allow you to manipulate JavaScript dates either in the browser or on the back end. You can't go wrong with either one.</p>
<h2 id="heading-forms">📋 Forms</h2>
<p>You may not need a form library in most cases if you're just building an app with a simple sign-up form, using the <code>required</code> prop on your inputs is usually all you need.</p>
<p>If you're building something more complex and have a lot of forms, <strong><a target="_blank" href="https://www.freecodecamp.org/news/how-to-create-forms-in-react-using-react-hook-form/">React Hook Form</a></strong> is a fully featured form library that allows you to validate form input and display errors with very minimal code.</p>
<p>Other form libraries, such as Formik and React Final Form, will give you the same functionality, but React Hook Form is a bit better because it has a more modern API based on hooks and usually requires less code.</p>
<h2 id="heading-drag-amp-drop">☔️ Drag &amp; Drop</h2>
<p>When it comes to adding drag and drop to your application, you almost certainly need a third-party library. The most popular choice in the past has been React Beautiful DnD. As of 2024, it is no longer receiving regular updates.</p>
<p>Going forward, a solid replacement for drag and drop is to use <strong><a target="_blank" href="https://dndkit.com/">DnD Kit</a></strong>. It's lightweight, very flexible, and the documentation includes a bunch of super helpful examples covering every use case you might have when implementing drag and drop.</p>
<h2 id="heading-mobile-apps">📱 Mobile Apps</h2>
<p>If you want to build a mobile app, the library to do so for React developers has always been <a target="_blank" href="https://www.freecodecamp.org/news/react-native-full-course-android-ios-development/">React Native</a>. There are some exciting libraries pushing the boundaries of React Native to extend to the web.</p>
<p><a target="_blank" href="https://expo.dev/"><strong>Expo</strong> is a tool similar to Vite</a>, but for making mobile React apps. It has great features like fast refresh, and with Expo Go, you can easily run your project on your own device as you develop it. Expo is making it easier to take your mobile code base and also deploy it to the web.</p>
<p>This is the end goal of other projects such as <strong><a target="_blank" href="https://tamagui.dev/">Tamagui</a></strong>, which you should also check out if you want to make a real native app that runs on Android, iOS, and the web.</p>
<p>If you have a React app that you've already written to run in the browser, the fastest way to have it run as a native app and launch it on the Apple App Store or Google Play Store is to use <strong><a target="_blank" href="https://capacitorjs.com/">Capacitor.js</a></strong>.</p>
<h2 id="heading-deployment">🚀 Deployment</h2>
<p>There are more ways than ever to deploy your React app. <a target="_blank" href="https://www.freecodecamp.org/news/deploy-react-app/">Vercel is probably the easiest platform</a> to deploy your React app with, whether it's client-rendered or server-rendered. They support just about every framework you can think of, including non-JavaScript languages. They have a generous hobby plan, and competitors in the same space include Netlify and Cloudflare Pages.</p>
<p>Cloudflare Pages might be a little bit trickier to set up, especially if you have a full-stack React project, but it is the most generous in terms of price out of all of these options. If you don't mind paying for a server, you can use something like Railway or Render, which is great to deploy to if you have a server that is separate from your React app.</p>
<h2 id="heading-the-1-library-to-know">✨ The #1 Library To Know</h2>
<p>Finally, the number one essential library you should know if you're a React developer in 2024 is <a target="_blank" href="https://www.freecodecamp.org/news/learn-typescript-beginners-guide/">TypeScript</a>. All of the frameworks I've mentioned include options to build a React app with TypeScript.</p>
<p>TypeScript is a tool that allows you to detect type errors in your JavaScript code to help you prevent runtime errors. You can build all of your React projects with just JavaScript, but at some point, you're going to either see the benefits of using TypeScript yourself or be looking at a codebase that has TypeScript in it.</p>
<p>I'd highly recommend you set aside some time to learn TypeScript. It's the most essential, the most in-demand tool to know as a React developer and can greatly improve your overall code quality.</p>
<h2 id="heading-become-a-professional-react-developer">🏆 Become a Professional React Developer</h2>
<p>Looking for the ultimate resource to learn React from start to finish?</p>
<p>✨ <strong><a target="_blank" href="https://www.thereactbootcamp.com">Introducing: The React Bootcamp</a></strong></p>
<p>The bootcamp features every resource to help you succeed with React:</p>
<ul>
<li>🎬 200+ in-depth videos</li>
<li>🕹️ 100+ hands-on React challenges</li>
<li>🛠️ 5+ impressive portfolio projects</li>
<li>📄 10+ essential React cheatsheets</li>
<li>🥾 A complete Next.js bootcamp</li>
<li>🖼️ A complete series of animated videos</li>
</ul>
<p>Click below to try the React Bootcamp for yourself.</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a><br><em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build an Admin Dashboard with React ]]>
                </title>
                <description>
                    <![CDATA[ Have you looked at interactive dashboards on websites like Stripe and thought, “How can I build something like this myself?” In this full-stack React and Next.js project, you’ll learn how to build a stunning admin dashboard from front to back. Our fi... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-admin-dashboard-react/</link>
                <guid isPermaLink="false">66d03755871ae63f179f6ba6</guid>
                
                    <category>
                        <![CDATA[ Next.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Tue, 30 Jan 2024 19:04:01 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/01/admin-dashboard-2.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Have you looked at interactive dashboards on websites like Stripe and thought, “How can I build something like this myself?”</p>
<p>In this full-stack React and Next.js project, you’ll learn how to build a stunning admin dashboard from front to back.</p>
<p>Our final admin dashboard will allow you to display and search through authenticated users within a users table and show important data using interactive bar and line charts.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/12/admin-dashboard-2.png" alt="Image" width="600" height="400" loading="lazy">
<em>The final version of our admin dashboard</em></p>
<p>In addition to learning about important Next.js concepts, you’ll become familiar with a bunch of powerful tools, including Prisma, PostgreSQL, Tremor, NextAuth and TailwindCSS.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a class="post-section-overview" href="#heading-tools-to-install">Tools to Install</a></li>
<li><a class="post-section-overview" href="#heading-how-to-create-a-postgres-database">Create Postgres Database</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/p/6fe70a96-0bef-4221-b4fd-8b624f7400ea/-how-to-set-up-prisma-schema">Set Up Prisma Schema</a></li>
<li><a class="post-section-overview" href="#heading-how-to-set-up-prisma-schema">Use the Prisma Client</a></li>
<li><a class="post-section-overview" href="#heading-how-to-connect-prisma-to-nextauth">Connect Prisma to NextAuth</a></li>
<li><a class="post-section-overview" href="#heading-how-to-build-the-apps-navbar">Build the App Navbar</a></li>
<li><a class="post-section-overview" href="#heading-how-to-display-account-info">Display the Account Info</a></li>
<li><a class="post-section-overview" href="#heading-how-to-protect-routes">Protect Routes</a></li>
<li><a class="post-section-overview" href="#heading-how-to-create-the-analytics-page">Create the Analytics Page</a></li>
<li><a class="post-section-overview" href="#heading-how-to-build-the-chart-component">Build the Chart Component</a></li>
<li><a class="post-section-overview" href="#heading-how-to-create-the-users-table">Create Users Table</a></li>
<li><a class="post-section-overview" href="#heading-how-to-search-for-users">Search for Users</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
<li><a class="post-section-overview" href="#heading-become-a-professional-react-developer">Become a Pro React Developer</a></li>
</ul>
<h2 id="heading-download-the-code">📁 Download the Code</h2>
<p>You can grab the starting and final code for the project we're going to build <a target="_blank" href="https://codebootcamp.nyc3.digitaloceanspaces.com/downloads/react-admin-dashboard-code.zip">here</a>.</p>
<h2 id="heading-tools-to-install">🛠️ Tools to Install</h2>
<p>To start building the admin dashboard, you'll need to have:</p>
<ul>
<li><a target="_blank" href="https://nodejs.org">Node.js</a> installed on your computer.</li>
<li>You should also have a code editor, such as <a target="_blank" href="https://code.visualstudio.com">Visual Studio Code</a>.</li>
<li>Finally, you’ll need to have a <a target="_blank" href="https://github.com">Github account</a>.</li>
</ul>
<p>Once you’ve grabbed the starting code and unzipped the start folder, drag it into Visual Studio Code, open up a terminal window and run the command:</p>
<pre><code class="lang-bash">npm install
</code></pre>
<p>This will install all of your app’s dependencies listed in the package.json file.</p>
<p>After doing that, you can start up your development server by running this command:</p>
<pre><code class="lang-bash">npm run dev
</code></pre>
<p>You can visit localhost:3000 in your browser to see your app up and running.</p>
<h2 id="heading-how-to-create-a-postgres-database">📀 How to Create a Postgres Database</h2>
<p>The backend of your app will consist of a Postgres database. We'll use Prisma to interact with that database and the authentication service will be NextAuth.</p>
<p>To create a new Postgres database, visit <a target="_blank" href="https://railway.app/new">railway.app/new</a>. You can make a PostgreSQL database for free without creating an account.</p>
<p>Once our database is created, click on it, then go to the Variables tab and copy the <code>DATABASE_URL</code> value.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/12/Screenshot-2023-12-11-at-3.11.11-PM-2.png" alt="Image" width="600" height="400" loading="lazy">
<em>Variables page for Postgres Database on Railway</em></p>
<p>After that, go to the <strong>.env.example</strong> file in your project, rename it to <strong>.env</strong>, and add the database url to the <code>DATABASE_URL</code> environment variable.</p>
<h2 id="heading-how-to-set-up-prisma-schema">✍️ How to Set Up Prisma Schema</h2>
<p>Now that we have a fully functional database, you need to connect it with Prisma. Prisma is what we'll use to model all our data. You can see this in the <strong>schema.prisma</strong> file.</p>
<p>The <strong>schema.prisma</strong> file, takes care of connecting to the database, setting up a Prisma client, and modelling all your data.</p>
<p>In your terminal, run the command <code>npx prisma db push</code>. This will push your schema to your Railway Postgres database.</p>
<p>This command also generates your Prisma client, which lets you get and change data in your database using Prisma.</p>
<h2 id="heading-how-to-use-the-prisma-client">How to Use the Prisma Client</h2>
<p>Within the <strong>lib</strong> folder, create a <strong>prisma.ts</strong> file. In this file, you'll pass the Prisma client to your entire app as a global variable.</p>
<pre><code class="lang-ts"><span class="hljs-comment">// lib/prisma.ts</span>
<span class="hljs-keyword">import</span> { PrismaClient } <span class="hljs-keyword">from</span> <span class="hljs-string">"@prisma/client"</span>;

<span class="hljs-keyword">declare</span> <span class="hljs-built_in">global</span> {
  <span class="hljs-keyword">var</span> prisma: PrismaClient;
}

<span class="hljs-keyword">const</span> client = globalThis.prisma || <span class="hljs-keyword">new</span> PrismaClient();
<span class="hljs-keyword">if</span> (process.env.NODE_ENV !== <span class="hljs-string">"production"</span>) globalThis.prisma = client;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> client;
</code></pre>
<p>Now you can simply import <code>client</code> into any file that needs to use Prisma and get data from your database.</p>
<h2 id="heading-how-to-connect-prisma-to-nextauth">🪝How to Connect Prisma to NextAuth</h2>
<p>The next step is connecting Prisma to NextAuth, which will be responsible for authenticating our users.</p>
<p>Within the root folder of your project, create a <strong>pages</strong> folder, which should contain an API folder, which should contain an <strong>auth</strong> folder. In the auth folder, place the file <code>[…nextauth].ts</code>.</p>
<p>Your folder structure should look like this:</p>
<pre><code class="lang-md">pages
 └ api
<span class="hljs-code">    └ auth
       └ [...nextauth].ts</span>
</code></pre>
<p>This is where you’ll set up NextAuth, which has to be connected to Prisma using the Prisma adapter.</p>
<p>In this file, you can paste in the following code:</p>
<pre><code class="lang-ts"><span class="hljs-comment">// pages/api/auth/[...nextauth].ts</span>
<span class="hljs-keyword">import</span> prisma <span class="hljs-keyword">from</span> <span class="hljs-string">"@/lib/prisma"</span>;
<span class="hljs-keyword">import</span> { PrismaAdapter } <span class="hljs-keyword">from</span> <span class="hljs-string">"@next-auth/prisma-adapter"</span>;
<span class="hljs-keyword">import</span> NextAuth, { AuthOptions } <span class="hljs-keyword">from</span> <span class="hljs-string">"next-auth"</span>;
<span class="hljs-keyword">import</span> GitHub <span class="hljs-keyword">from</span> <span class="hljs-string">"next-auth/providers/github"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> authOptions: AuthOptions = {
  adapter: PrismaAdapter(prisma),
  providers: [
    GitHub({
      clientId: process.env.GITHUB_CLIENT_ID!,
      clientSecret: process.env.GITHUB_CLIENT_SECRET!,
    }),
  ],
  debug: process.env.NODE_ENV === <span class="hljs-string">"development"</span>,
  secret: process.env.NEXTAUTH_SECRET,
  callbacks: {
    <span class="hljs-keyword">async</span> signIn() {
      <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    },
    <span class="hljs-keyword">async</span> redirect() {
      <span class="hljs-keyword">return</span> <span class="hljs-string">"/"</span>;
    },
  },
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> NextAuth(authOptions);
</code></pre>
<p>To authenticate users with Github, you’ll use the Github provider, which requires a client ID and client secret.</p>
<p>To retrieve these, you’ll need to log into your Github account and use <a target="_blank" href="https://github.com/settings/applications/new">this link</a> to create a new Github OAuth App.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/12/Screenshot-2023-12-11-at-4.16.40-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Registering a Github OAuth App</em></p>
<p>Add a unique application name such as “Admin Dashboard”. The homepage URL will be <a target="_blank" href="http://localhost:3000">http://localhost:3000</a>, where your application runs in development. This will be your production URL if you choose to deploy this application.</p>
<p>The callback URL is included in the <strong>.env</strong> file. The catch-all route we set up allows this callback URL to be used.</p>
<p>Next, register the application to receive your client ID, which you'll set to the <code>GITHUT_CLIENT_ID</code> environment variable. Generate a new client secret, copy it, and include it under <code>GITHUB_CLIENT_SECRET</code>.</p>
<p>Finally, we need a secret. Go back to your <strong>.env</strong> file. I've included a command to generate a unique string:</p>
<pre><code class="lang-bash">openssl rand -hex 32
</code></pre>
<p>Run this command in your terminal, then paste the generated string for <code>NEXT_AUTH_SECRET</code>.</p>
<p>With all of the environment variables we have provided, Next Auth is set up successfully and can be used to authenticate users and protect routes throughout our application.</p>
<h2 id="heading-how-to-build-the-apps-navbar">🧭 How to Build the App's Navbar</h2>
<p>All of the components in our app are going to be placed in the “components” folder.</p>
<p>Let’s include a Navbar component across every page in the app. To do that, we can add it to the root layout component (<code>layout.tsx</code> in the app folder).</p>
<pre><code class="lang-tsx">// app/layout.tsx
import Navbar from '@/components/Navbar';
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import { Suspense } from 'react';
import './globals.css';

const inter = Inter({ subsets: ['latin'] })

export const metadata: Metadata = {
  title: 'Admin Dashboard',
}

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    &lt;html lang="en"&gt;
      &lt;body className={inter.className}&gt;
         &lt;Navbar /&gt;
        {children}
      &lt;/body&gt;
    &lt;/html&gt;
  )
}
</code></pre>
<p>Let’s create a sign in link in the <code>Navbar</code> component so users can authenticate themselves.</p>
<p>In Navbar, use a function from NextAuth to initiate the sign-in process. Find the "sign-in" text and implement functionality for both desktop and mobile views.</p>
<pre><code class="lang-tsx">// components/Navbar.tsx

// ...
&lt;Menu.Item&gt;
  {({ active }) =&gt; (
    &lt;button
      className={classNames(
        active ? "bg-gray-100" : "",
        "flex w-full px-4 py-2 text-sm text-gray-700"
      )}
      onClick={() =&gt; signIn("github")}
    &gt;
      Sign in
    &lt;/button&gt;
  )}
&lt;/Menu.Item&gt;
// ...
</code></pre>
<p>To use this <code>signIn</code> function, add above the Navbar component:</p>
<pre><code class="lang-tsx">import { signIn, signOut } from "next-auth/react";
</code></pre>
<p>Selecting sign-in should redirect to a GitHub hosted page for users to authenticate themselves. If users are authenticated properly, they’ll navigate back to the home page and will be logged in.</p>
<p>You can check and see if a new user is created after logging by running the command <code>npx prisma studio</code>. The Prisma Studio allows you to view and manage model data, including accounts, sessions, and users.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/12/Screenshot-2023-12-11-at-4.22.30-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Prisma Studio</em></p>
<h2 id="heading-how-to-display-account-info">How to Display Account Info</h2>
<p>The next step is displaying the GitHub account information, like the email and avatar image, in place of the dummy avatar. For this, we need a client component due to certain libraries, such as the headless UI components.</p>
<p>Create a new component in the <strong>components</strong> folder called <strong>Nav.tsx</strong>:</p>
<pre><code class="lang-tsx">// components/Nav.tsx
import Navbar from "@/components/Navbar";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { getServerSession } from "next-auth";

export default async function Nav() {
  const session = await getServerSession(authOptions);

  return &lt;Navbar user={session?.user} /&gt;;
}
</code></pre>
<p>Here, we are getting the current session of the logged in user and passing it to the Navbar component on the user prop.</p>
<p>Within <code>Navbar</code>, we need to receive that prop and declare its type using the type <code>Props</code>. </p>
<pre><code class="lang-tsx">// components/Navbar.tsx
import { Session } from "next-auth";

type Props = {
  user: Session["user"];
};

export default function Navbar({ user }: Props) {
// ...
</code></pre>
<p>Since <code>Nav</code> is now wrapping our <code>Navbar</code> component, replace the <code>Navbar</code> with <code>Nav</code> in your <strong>layout.tsx</strong> file:</p>
<pre><code class="lang-tsx">// app/layout.tsx
import Nav from '@/components/Nav';

// ...
export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    &lt;html lang="en"&gt;
      &lt;body className={inter.className}&gt;
        &lt;Nav /&gt;
        {children}
      &lt;/body&gt;
    &lt;/html&gt;
  )
}
</code></pre>
<p>Save all files and log the session within <code>Nav</code>. Refresh the app and check logs for user data. Logging the user in the navbar should display user data in the browser console.</p>
<p>To display the logged-in user data instead of the default avatar, use a ternary statement in the navbar.</p>
<p>If <code>user.image</code> is present, return an image from “next/image” with appropriate classes and attributes. </p>
<p>Also, set the source to <code>user.image</code>, height and width to 32, and alt text to <code>user.name</code> or "avatar" as a fallback.</p>
<p>If the image isn't present or the user isn't authenticated, use the <code>Avvvatars</code> component with the value "U".</p>
<pre><code class="lang-tsx">// components/Navbar.tsx

// ...
&lt;Menu.Button className="flex rounded-full bg-white text-sm focus:outline-none focus:ring-2 focus:ring-slate-500 focus:ring-offset-2"&gt;
  &lt;span className="sr-only"&gt;Open user menu&lt;/span&gt;
  {user?.image ? (
    &lt;Image
      className="h-8 w-8 rounded-full"
      src={user.image}
      height={32}
      width={32}
      alt={user?.name ?? 'avatar'}
    /&gt;
  ) : (
    &lt;Avvvatars value={'U'} /&gt;
  )}
&lt;/Menu.Button&gt;
// ...
</code></pre>
<p>For the menu items component, add the user to the ternary statement, enabling the display of the "sign out" button. Implement an onClick event to call 'sign out' when clicked.</p>
<pre><code class="lang-tsx">// components/Navbar.tsx

// ...
&lt;Menu.Items className="absolute right-0 z-10 mt-2 w-48 origin-top-right rounded-md bg-white py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"&gt;
  {user ? (
    &lt;Menu.Item&gt;
      {({ active }) =&gt; (
        &lt;button
          className={classNames(
            active ? "bg-gray-100" : "",
            "flex w-full px-4 py-2 text-sm text-gray-700",
          )}
          onClick={() =&gt; signOut()}
        &gt;
          Sign out
        &lt;/button&gt;
      )}
    &lt;/Menu.Item&gt;
  ) : (
// ...
</code></pre>
<p>This approach demonstrates fetching data on the server and passing it to a client component. It's an effective way to handle user data and display it in your application.</p>
<h2 id="heading-how-to-protect-routes">🛡️ How to Protect Routes</h2>
<p>The final step in authentication is protecting routes. We have a dashboard, a users page (which is the homepage), and an analytics page. The analytics page, which we'll build out, needs to be password-protected so that only authenticated users can access it.</p>
<p>To protect this route, fetch data on the server using the <code>getServerSession</code> function. But to protect the <code>/analytics</code> route, you'll need to create it within the app folder. Add a folder named <strong>analytics</strong> and within it, a <strong>page.tsx</strong> file.</p>
<p>We have to protect the <code>AnalyticsPage</code> based on the session status. If there's no authenticated user, we redirect to the login route, which is <code>/api/auth/sign-in</code>.</p>
<pre><code class="lang-tsx">// app/analytics/page.tsx
import Analytics from "@/components/Analytics";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";

export default async function AnalyticsPage() {
  const session = await getServerSession(authOptions);

  if (!session) {
    redirect("api/auth/signin");
  }

  return &lt;Analytics /&gt;;
}
</code></pre>
<p>This basic pattern is essential for protecting content in an admin dashboard. With authentication now covered, we can move on to building the user interface.</p>
<h2 id="heading-how-to-create-the-analytics-page">📈 How to Create the Analytics Page</h2>
<p>We'll use a library called Tremor to build graphs and charts on the analytics page. Tremor allows us to create dashboards quickly, although we won't source the dashboard data from our database.</p>
<p>We’ll use the Grid, Title, and Flex components for layout and styling. We'll also use the Metric and Text components from Tremor for displaying stats and labels within a Grid of cards.</p>
<pre><code class="lang-tsx">// components/Analytics.tsx
"use client";

import Chart from "@/components/Chart";
import { BarList, Card, Flex, Grid, Metric, Text, Title } from "@tremor/react";

const app = [
  { name: "/shop", value: 789 },
  { name: "/product-features", value: 676 },
  { name: "/about", value: 564 },
  { name: "/login", value: 234 },
  { name: "/downloads", value: 191 },
];

const data = [
  {
    category: "Mobile App",
    stat: "2,543",
    data: app,
  },
];

export default function Analytics() {
  return (
    &lt;main className="p-4 md:p-10 mx-auto max-w-7xl"&gt;
      &lt;Grid numItemsSm={2} numItemsLg={3} className="gap-6"&gt;
        {data.map((item) =&gt; (
          &lt;Card key={item.category}&gt;
            &lt;Title&gt;{item.category}&lt;/Title&gt;
            &lt;Flex
              justifyContent="start"
              alignItems="baseline"
              className="space-x-2"
            &gt;
              &lt;Metric&gt;{item.stat}&lt;/Metric&gt;
              &lt;Text&gt;Total views&lt;/Text&gt;
            &lt;/Flex&gt;
            &lt;Flex className="mt-6"&gt;
              &lt;Text&gt;Pages&lt;/Text&gt;
              &lt;Text className="text-right"&gt;Views&lt;/Text&gt;
            &lt;/Flex&gt;
            &lt;BarList
              data={item.data}
              valueFormatter={(number: number) =&gt;
                Intl.NumberFormat("us").format(number).toString()
              }
              className="mt-2"
            /&gt;
          &lt;/Card&gt;
        ))}
      &lt;/Grid&gt;
      &lt;Chart /&gt;
    &lt;/main&gt;
  );
}
</code></pre>
<h2 id="heading-how-to-build-the-chart-component">📊 How to Build the Chart Component</h2>
<p>After setting up the top grid with bar charts, let’s set up the chart at the bottom using the AreaChart component from Tremor.</p>
<p>The area chart will include data over different months, comparing sales and profit.</p>
<pre><code class="lang-tsx">// components/Chart.tsx
"use client";

import { Card, AreaChart, Title, Text } from "@tremor/react";

const data = [
  {
    Month: "Jan 21",
    Sales: 2890,
    Profit: 2400,
  },
  {
    Month: "Feb 21",
    Sales: 1890,
    Profit: 1398,
  },
  {
    Month: "Jan 22",
    Sales: 3890,
    Profit: 2980,
  },
];

export default function Chart() {
  return (
    &lt;Card className="mt-8"&gt;
      &lt;Title&gt;Performance&lt;/Title&gt;
      &lt;Text&gt;Comparison between Sales and Profit&lt;/Text&gt;
      &lt;AreaChart
        className="mt-4 h-80"
        data={data}
        categories={["Sales", "Profit"]}
        index="Month"
        colors={["indigo", "fuchsia"]}
        valueFormatter={(number: number) =&gt;
          `$ ${Intl.NumberFormat("us").format(number).toString()}`
        }
        yAxisWidth={60}
      /&gt;
    &lt;/Card&gt;
  );
}
</code></pre>
<h2 id="heading-how-to-create-the-users-table">👥 How to Create the Users Table</h2>
<p>Now that we’ve taken care of our analytics page, let's address the users' table.</p>
<p>This table will display users from our Postgres database. We'll fetch and query all users using the Prisma client and show how to search for users by name or other fields.</p>
<p>We’ll begin by making a simple table with the help of Tremor components in the <code>UsersTable</code> component. If you’re familiar with HTML table elements, this should look very familiar to you.</p>
<p>We’re going to make rows for the <code>name</code>, <code>email</code> and <code>created_at</code> values for each of the users and display those values in the table body:</p>
<pre><code class="lang-tsx">// components/UsersTable.tsx
import { User } from "@prisma/client";
import {
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableHeaderCell,
  TableRow,
} from "@tremor/react";

type Props = {
  users: User[];
};

export default function UsersTable({ users }: Props) {
  return (
    &lt;Table&gt;
      &lt;TableHead&gt;
        &lt;TableRow&gt;
          &lt;TableHeaderCell&gt;Name&lt;/TableHeaderCell&gt;
          &lt;TableHeaderCell&gt;Email&lt;/TableHeaderCell&gt;
          &lt;TableHeaderCell&gt;Created At&lt;/TableHeaderCell&gt;
        &lt;/TableRow&gt;
      &lt;/TableHead&gt;
      &lt;TableBody&gt;
        {users.map((user) =&gt; (
          &lt;TableRow key={user.id}&gt;
            &lt;TableCell&gt;{user.name}&lt;/TableCell&gt;
            &lt;TableCell&gt;{user.email}&lt;/TableCell&gt;
            &lt;TableCell&gt;
              {new Intl.DateTimeFormat("en-US").format(user.createdAt)}
            &lt;/TableCell&gt;
          &lt;/TableRow&gt;
        ))}
      &lt;/TableBody&gt;
    &lt;/Table&gt;
  );
}
</code></pre>
<h2 id="heading-how-to-search-for-users">🔎 How to Search for Users</h2>
<p>To make our table searchable, we’ll go back out to the home page and build the basic UI for the search component.</p>
<pre><code class="lang-tsx">// components/Search
export default function Search({ query }: Props) {
  return (
    &lt;div className="relative mt-5 max-w-md"&gt;
      &lt;label htmlFor="search" className="sr-only"&gt;
        Search
      &lt;/label&gt;
      &lt;div className="rounded-md shadow-sm"&gt;
        &lt;div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3"&gt;
          &lt;SearchIcon className="mr-3 h-4 w-4 text-gray-400" /&gt;
        &lt;/div&gt;
        &lt;input
          type="text"
          name="search"
          autoComplete="off"
          id="search"
          className="h-10 block w-full rounded-md border border-gray-200 pl-9 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
          placeholder="Search by name..."
          onChange={(event) =&gt; handleSearch(event.target.value)}
          defaultValue={query}
        /&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  );
}
</code></pre>
<p>Since Next.js users server components by default, we can use URL state to initiate queries.</p>
<p>Within a new function called <code>handleSearch</code>, we can update the URL by adding a query parameter called <code>q</code> and set the query that the user typed into the input as the value.</p>
<p>That means that when the user types into the input, the search query will be added to the URL.</p>
<pre><code class="lang-tsx">// components/Search.tsx
import { usePathname, useRouter } from "next/navigation";
import { useTransition } from "react";

type Props = {
  query?: string;
};

export default function Search({ query }: Props) {
  const router = useRouter();
  const pathname = usePathname();
  const [isPending, startTransition] = useTransition();

  function handleSearch(value: string) {
    const params = new URLSearchParams(window.location.search);

    if (value) {
      params.set("q", value);
    } else {
      params.delete("q");
    }

    startTransition(() =&gt; {
      router.replace(`${pathname}?${params.toString()}`);
    });
  }
// ...
</code></pre>
<p>Back in our server component, <strong>app.tsx</strong>, we'll use the search params (which are provided as props in page components) to query our database with Prisma.</p>
<p>We can modify the <code>findMany</code> method to search for users according to <code>name</code> and <code>email</code> using the “where” filter. We can also do it in a case-insensitive way using <code>mode: insensitive</code>.</p>
<pre><code class="lang-tsx">// app/page.tsx
// ...
type Props = {
  searchParams: {
    q?: string;
  };
};

export default async function Home({ searchParams }: Props) {
  const query = searchParams.q;
  const users = await prisma.user.findMany({
    where: {
      name: {
        contains: query,
        mode: "insensitive",
      },
      email: {
        contains: query,
        mode: "insensitive",
      },
    },
  });
// ...
</code></pre>
<p>Finally, we are using the <code>useTransition</code> hook to change the URL in a performant way.</p>
<p>Back in the <code>Search</code> component, you can add a loading spinner to the end of your input to tell the user that we are in the process of changing the URL.</p>
<pre><code class="lang-tsx">// components/Search.tsx
// ...
  {isPending &amp;&amp; (
    &lt;div className="absolute right-0 top-0 bottom-0 flex items-center justify-center"&gt;
      &lt;RotateCwIcon className="animate-spin -ml-1 mr-3 h-5 w-5 text-gray-700" /&gt;
    &lt;/div&gt;
  )}
&lt;/div&gt;
</code></pre>
<p>This approach demonstrates changing URL state with each keystroke in a performant way, especially important when using server components in Next.js.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In conclusion, building this admin dashboard covers many aspects, from setting up authentication with NextAuth and Prisma to creating a user-friendly interface with Tremor.</p>
<p>These tools and techniques offer a comprehensive way to create flexible and visually appealing dashboards. Feel free to use this admin dashboard in your projects.</p>
<p>Thank you for following along and I hope this guide has been helpful!</p>
<h2 id="heading-become-a-professional-react-developer">🏆 Become a Professional React Developer</h2>
<p>Looking for the ultimate resource to learn React from start to finish?</p>
<p>✨ <strong><a target="_blank" href="https://www.thereactbootcamp.com">Introducing: The React Bootcamp</a></strong></p>
<p>The bootcamp features every resource to help you succeed with React:</p>
<ul>
<li>🎬 200+ in-depth videos</li>
<li>🕹️ 100+ hands-on React challenges</li>
<li>🛠️ 5+ impressive portfolio projects</li>
<li>📄 10+ essential React cheat sheets</li>
<li>🥾 A complete Next.js bootcamp</li>
<li>🖼️ A complete series of animated videos</li>
</ul>
<p>Click below to try the React Bootcamp for yourself.</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a><br><em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Create a React App in 2024 ]]>
                </title>
                <description>
                    <![CDATA[ In 2024, there are more ways than ever to get your React projects started. But which one should you choose? In this article, I'm going to break down all of the major ways you can use to create a React app and which one you should pick based off of ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-create-a-react-app-in-2024/</link>
                <guid isPermaLink="false">66d03779dcd3a41034854bbe</guid>
                
                    <category>
                        <![CDATA[ Developer Tools ]]>
                    </category>
                
                    <category>
                        <![CDATA[ projects ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Fri, 26 Jan 2024 13:44:45 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/01/build-react-app-2024.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In 2024, there are more ways than ever to get your React projects started. But which one should you choose?</p>
<p>In this article, I'm going to break down all of the major ways you can use to create a React app and which one you should pick based off of your project's needs.</p>
<p>I'll also include a quick guide at the end to show you exactly how to choose between each according to the type of project you're building.</p>
<p>Let's get started!</p>
<h2 id="heading-why-you-shouldnt-use-create-react-app">❌ Why You Shouldn't Use Create React App</h2>
<p>In 2023, the Create React App tool was deprecated, which means that it was no longer being maintained. Create React App has been the go-to way to make a new React project, but it's been dethroned by a number of different alternatives.</p>
<p>For that reason, Create React App is not an option I would recommend for creating a new React project in 2024.</p>
<h2 id="heading-how-to-create-a-react-app-with-vite">💨 How to Create a React App with Vite</h2>
<p>You may be asking, "What's a good replacement for Create React App?" That option is Vite.</p>
<p>Vite is ideal for making client-rendered React projects that run exclusively in the browser.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/vite.png" alt="Image" width="600" height="400" loading="lazy">
<em>Vite docs home page</em></p>
<p>To spin up a new React project with Vite, you just have to run a single command:</p>
<pre><code class="lang-bash">npm create vite@latest my-react-app -- --template react
</code></pre>
<p>The great thing about Vite is, as its name indicates, it's much faster than virtually every alternative. Where Vite really shines is how quickly it runs in development.</p>
<p>Vite is unopinionated, however, which means you will likely need to install a suite of third-party libraries for basic functionality, like routing and data fetching.</p>
<p>If your application doesn't have a server or you are using an external API and it doesn't need server-side rendering, Vite is a perfect choice.</p>
<p>Additionally, Vite comes with its own config file, <strong>vite.config.js</strong>, which might require reading the documentation in order to configure things such as environment variables, build options, and image options.</p>
<h2 id="heading-how-to-create-a-react-app-with-nextjs">🥞 How to Create a React App with Next.js</h2>
<p>If you're looking for a way to build a React app that gives you a single-page app (SPA) experience but with server-side rendering and server components, Next.js is your choice.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/nextjs.png" alt="Image" width="600" height="400" loading="lazy">
<em>Next.js docs home page</em></p>
<p>Next.js is the only option at the moment that comes with server components, which allows you to mark a component as <code>async</code> and <code>await</code> in some operation on the server.</p>
<pre><code class="lang-tsx">async function getData() {
  const res = await fetch('https://api.example.com/...');
  return res.json();
}

export default async function Page() {
  const data = await getData();

  return &lt;main&gt;{data}&lt;/main&gt;;
}
</code></pre>
<p>The benefit of server components is that you don't have to show a loading spinner in your app before fetching data. Server components allow you to ship far less JavaScript to the client, which leads to faster load times for your users.</p>
<p>Server components do require that you have a server, however, this means that it can't be deployed as simply as a client-rendered React app made with Vite.</p>
<p>Next.js is powerful because it comes with a ton of built-in features, such as a dedicated file-based routing, image optimization, and font loading, to name a few.</p>
<p>Next.js also allows you to tap into server actions, which is a new React feature that allows you to run server code by calling a function.</p>
<pre><code class="lang-tsx">// Server Component
export default function Page() {
  // Server Action
  async function create() {
    'use server'

    // ...
  }

  return (
    // ...
  )
}
</code></pre>
<p>Next.js also has route handlers, which lets you to make HTTP requests to an API endpoint. This is something that client-rendered React apps can't do, because there's no server.</p>
<p>With all of Next.js' benefits, it comes with a steeper learning curve. There are a number of Next.js-specific concepts that may seem to go against some React concepts you've already learned.</p>
<p>For example, within server components, you can't use React Hooks. This means that you have to rely on patterns such as storing state in the URL.</p>
<p>Despite the learning curve, Next.js is the most popular React framework and is relied upon to build impressive React apps that power small startups to Fortune 500 companies.</p>
<p>If you want to make something impressive with React, you can certainly do it with Next.js.</p>
<h2 id="heading-how-to-create-a-react-app-with-remix">💿 How to Create a React App with Remix</h2>
<p>Remix, like Next.js, is a React-based framework that has a different focus on web standards to deliver a better user experience. Remix allows you to also write server and client React code.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/remix.png" alt="Image" width="600" height="400" loading="lazy">
<em>Remix docs home page</em></p>
<p>Remix prides itself on serving static and dynamic content faster than Next.js. This means it's equally good at building full-stack applications as well as static websites.</p>
<p>Instead of server components and server actions, Remix simply has actions. Actions allows you to handle data mutations on your server, which is anything that isn't a GET request. Actions are just simple functions with the name action.</p>
<p>To get data, you use simple functions called loaders. React Remix uses React Router under the hood. So if you're comfortable with React Router, you'll likely feel at home with Remix as well.</p>
<pre><code class="lang-tsx">export async function loader() {
  return json(await fakeGetTodos());
}

export default function Todos() {
  const data = useLoaderData&lt;typeof loader&gt;();
  return (
    &lt;div&gt;
      &lt;TodoList todos={data} /&gt;
      &lt;Form method="post"&gt;
        &lt;input type="text" name="title" /&gt;
        &lt;button type="submit"&gt;Create Todo&lt;/button&gt;
      &lt;/Form&gt;
    &lt;/div&gt;
  );
}
</code></pre>
<p>Remix is a bit more stable than Next.js and has a less steep learning curve, still allowing you to build just as impressive applications, with the only downside being that it's not nearly as popular as Next.js. So it doesn't have the same community support and libraries around it.</p>
<p>But if you do want something with server-side rendering and client-side rendering, Remix still remains a great option to build your next React project.</p>
<h2 id="heading-how-to-create-a-react-app-with-astro">🚀 How to Create a React App with Astro</h2>
<p>The newest way to build a React project is definitely the most performant. React apps can also be built using a framework called Astro.  </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/astro.png" alt="Image" width="600" height="400" loading="lazy">
<em>Astro docs home page</em></p>
<p>Astro's goal is deliver content to users quickly through something called "island architecture".</p>
<p>In short, this means that JavaScript is loaded only when the user needs them, making for a much more optimal user experience. If you want the fastest website possible, I'd highly recommend looking at Astro.</p>
<p>Astro supports server-side rendering and is great for SEO-focused websites that are largely static. However, what's neat about Astro is that it can also run code on the server if you choose to. It's not as popular to build fully dynamic, full-stack applications with Astro, but it is possible to do so.</p>
<p>Astro is also very flexible as it's not even tied to React. You don't need to use React whatsoever to build an Astro app, and you can use React alongside other frameworks such as Vue and Svelte within the same app.</p>
<p>If you're building a website that has posts or content that uses markdown or MDX, Astro should be your top choice. It uses a feature called "collections" to describe all the data within your markdown files so that you know exactly what content is going to be rendered in your React components.</p>
<p>Astro is gaining rapidly in popularity, and it's probably the best choice out there if you are interested in making a static website that doesn't need a database or authentication, or a website that is largely static.</p>
<h2 id="heading-so-what-should-i-choose">🤔 So What Should I Choose?</h2>
<p>If you've read up to this point and you're still trying to figure out which framework would be best for you to build a React project in 2024, here's the rundown:</p>
<ul>
<li>If you're just starting out and learning the React basics but want to build a simple or medium-sized project, stick with Vite.</li>
<li>If you want a full-stack framework with all the bells and whistles, like server components, and you don't mind spending time learning additional concepts, check out Next.js.</li>
<li>If you've tried Next.js and find some of its concepts difficult to understand, but still want to build a full-stack React application, definitely look into Remix.</li>
<li>Finally, if you have a static or content-driven website, and you don't really need a database or authentication, I would highly recommend using Astro.</li>
</ul>
<h2 id="heading-become-a-professional-react-developer">🏆 Become a Professional React Developer</h2>
<p>Looking for the ultimate resource to learn React from start to finish?</p>
<p>✨ <strong><a target="_blank" href="https://www.thereactbootcamp.com">Introducing: The React Bootcamp</a></strong></p>
<p>The bootcamp features every resource to help you succeed with React:</p>
<ul>
<li>🎬 200+ in-depth videos</li>
<li>🕹️ 100+ hands-on React challenges</li>
<li>🛠️ 5+ impressive portfolio projects</li>
<li>📄 10+ essential React cheat sheets</li>
<li>🥾 A complete Next.js bootcamp</li>
<li>🖼️ A complete series of animated videos</li>
</ul>
<p>Click below to try the React Bootcamp for yourself.</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a><br><em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ 7 React Projects to Build in 2024 ]]>
                </title>
                <description>
                    <![CDATA[ To be confident with using React, you need to build real-world projects. But what projects are worth building in 2024? I have put together a list of seven projects that I think are ideal for becoming a confident React developer, from simple to comple... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/react-projects-to-build-in-2024/</link>
                <guid isPermaLink="false">66d037d5871ae63f179f6bc3</guid>
                
                    <category>
                        <![CDATA[ projects ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Tue, 16 Jan 2024 12:07:51 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/01/mugshotbot.com_customize_color-orange-mode-light-pattern-bubbles-theme-two_up-url-https___gifcoins.io--1-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>To be confident with using React, you need to build real-world projects. But what projects are worth building in 2024?</p>
<p>I have put together a list of seven projects that I think are ideal for becoming a confident React developer, from simple to complex applications. This will give you some inspiration for what apps to build.</p>
<p>I'll also walk you through the entire tech stack I would use to build each project, as well as a summary of how to build each one step by step.</p>
<p>Let's get started!</p>
<h2 id="heading-chatgpt-ai-app">🤖 ChatGPT AI App</h2>
<p>As ChatGPT becomes more powerful, you can build impressive applications using the ChatGPT API.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/chatgpt.png" alt="Image" width="600" height="400" loading="lazy">
<em>ChatGPT AI app: Draw-a-UI</em></p>
<p>This is a great starter app because, for most applications, all you need to do is send text or an image to the ChatGPT API, give it some instructions, and it'll send a response back to you.</p>
<p>You could use the ChatGPT API to build a text summarizer, a translation app, an app that explains what a code snippet does. The possibilities are really endless.</p>
<p>One simple ChatGPT-powered AI app that I've built is "Draw a UI", where you can draw a quick mockup of a user interface, send it to ChatGPT, and it'll actually send you back the HTML that was generated according to your screenshot!</p>
<p>I would build this application using Next.js as well as the <code>tldraw</code> npm package, which allows you to draw pictures in your React app.</p>
<p>Next, send that screenshot to a Next.js route handler on the back end that uses the <strong>openai</strong> npm package to talk with ChatGPT, and then sends you back the HTML code.</p>
<h2 id="heading-personal-website">👨‍💻 Personal Website</h2>
<p>If you're not ready to build something very complex yet, a personal website is a great starting point. You can use it as a way to get comfortable working with JSX and CSS in React.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/portfolio.png" alt="Image" width="600" height="400" loading="lazy">
<em>A personal website made with Next.js and TailwindCSS</em></p>
<p>Learn how to create basic components, add images, links to your social media profiles, and so on. When you start building more projects, you can show them off on your website.</p>
<p>The great thing about a personal website is that you can extend it as much as you want. You can add your own integrated blog, or you can talk about things that you've learned or what you're working on at the moment.</p>
<p>In order to build your personal website, I would recommend using Next.js because it makes it so easy to build individual pages that are statically rendered, which is good for SEO.</p>
<p>For the images, you can use the integrated <code>next/image</code> library. And for making a blog, I'd highly recommend using the ContentLayer package , which you can use to write all of your blog posts as markdown or MDX.</p>
<p>ContentLayer is great because it makes your markdown content type safe so you know what data each blog post includes. This is also a great way to get started with TypeScript in React, although it may seem intimidating at first.</p>
<h2 id="heading-chat-app">💬 Chat App</h2>
<p>A truly dynamic web application would be a chat app, something that you likely use every day. It's good to build applications that you're familiar with because it gives you a good idea of what parts it's composed of.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/chat.png" alt="Image" width="600" height="400" loading="lazy">
<em>Chat App made with React, similar to WhatsApp</em></p>
<p>A chat app is simple in terms of its components. You only need a messages area, an input to type new messages, and a list of people to chat with.</p>
<p>It's a great project because it can be as simple or as complex as you like. To build something like this, I would use Vite to create the React project and power the backend with Supabase.</p>
<p>You don't need any server-side code here with Supabase, and it also gives you real-time chat functionality, entirely free. You can add authentication to identify users (using Supabase Auth), and put all the created users in a sidebar to chat with.</p>
<p>Then you can create a table for messages and send them off to Supabase whenever someone types in some text. To extend it further, you could make it possible for them to add images and video with Supabase Storage.</p>
<p>Finally, you can display messages in real-time using subscriptions depending on to the user you're chatting with.</p>
<h2 id="heading-e-commerce-app">💳 E-Commerce App</h2>
<p>The next type of app we'll talk about is an e-commerce app. </p>
<p>An e-commerce app can be used for selling physical or digital products with a one-time purchase feature.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/ecommerce.png" alt="Image" width="600" height="400" loading="lazy">
<em>An E-Commerce app with physical goods, made with Next.js</em></p>
<p>After the purchase, you need to deliver it to the customer. The e-commerce app could be very complex, but it doesn't have to be at the start. You just need to make a basic storefront with your products.</p>
<p>Give them an associated image with a description, as well as a buy button. You don't even need to add authentication. To build this, I would use Next.js integrated with Stripe to handle purchases.</p>
<p>The inventory system doesn't have to be very complex if you're selling a physical product. It could be as simple as having a number in a database that can be updated whenever stock is added and decreased whenever someone makes a purchase.</p>
<h2 id="heading-online-marketplace">🛒 Online Marketplace</h2>
<p>The online marketplace is an extension of the e-commerce app. It's a bit more complex because you're adding more products. </p>
<p>You might also consider adding extra features such as reviews, which are essential to online shopping.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/marketplace.png" alt="Image" width="600" height="400" loading="lazy">
<em>Next.js store with an integrated shopping cart and reviews</em></p>
<p>The challenge in this case is adding a shopping cart. To make for a good user experience on a website with many products, you want to allow customers to add multiple products to their cart.</p>
<p>To add a shopping cart, I would use the same stack as before, Next.js and Stripe, to handle managing and purchasing the products. Fortunately, there's a great package called use-shopping-cart, which integrates perfectly with Stripe checkout. </p>
<p>You can use it to make a complete shopping cart with the ability to add and remove items, as well as clear the cart right out of the box.</p>
<p>For reviews, you could add a database layer like Supabase, or you could outsource reviews to a third-party service that allows you to integrate reviews, like Trustpilot, for example.</p>
<h2 id="heading-saas-app-software-as-a-service">🚚 SaaS App (Software as a Service)</h2>
<p>The final evolution in doing sales online with React is a SaaS application.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/saas.png" alt="Image" width="600" height="400" loading="lazy">
<em>Gumroad inspired SaaS app made with Next.js</em></p>
<p>In this app, you provide customers access to a certain software service that you've made, usually for a monthly or yearly subscription fee.</p>
<p>You can create a SaaS application as a paid version of an app that you've already built, such as the AI app or the chat app.</p>
<p>In short, if you can build an application that users would pay for, either to be more productive, for entertainment, or to educate them, then all you need to do to make a SaaS app is to charge those customers a fee for using it.</p>
<p>A SaaS app could charge users based on usage or over a set period of time, such as a month or a year. </p>
<p>This can be done with the help of Stripe or a merchant of records such as Paddle, which makes taxes easier. Both of them can handle subscriptions.</p>
<p>I would recommend using Stripe Checkout to allow customers to manage their subscription and cancel it if necessary.</p>
<h2 id="heading-real-world-app-clone">📱Real-World App Clone</h2>
<p>Finally, the most ambitious project would be to build a clone of an app that you really like or that you use every day.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/clone.png" alt="Image" width="600" height="400" loading="lazy">
<em>A clone of the YouTube web app with React</em></p>
<p>An app clone is very difficult because you're usually cloning something that a big company is based off of. However, doing so is a great approach to leveling up your skills as a React developer because you have to think through about how a service is made.</p>
<p>If you were to clone something like YouTube, for example, you're not only going to build out the user interface and have it look like YouTube's, but you'll also need the functionalities that YouTube has, such as menus and drawers and notifications, and the ability to add and view videos, comments, likes, and so on.</p>
<p>If I were to build a YouTube clone, I would use either Supabase or a MySQL database like PlanetScale, along with Next.js, and authentication with Supabase or NextAuth.</p>
<p>I would build the user interface with TailwindCSS and Radix UI. Radix is a library that provides simple (primitive) components that can be easily styled, but are fully functional, which saves you a bunch of time.</p>
<p>To upload videos and media, I would use a platform dedicated to streaming videos such as Mux, which provides a great developer API.</p>
<p>For storing images and all other media and attachments, I would use Supabase Storage.</p>
<p>How far you take it really depends on your ambition and whether you want it to be a business of your own or a great portfolio project to show off to potential employers.</p>
<h2 id="heading-want-to-build-all-the-projects">🛠️ Want to Build All the Projects?</h2>
<p>You can learn exactly how to build each project within this list inside the all-new React Bootcamp:</p>
<p>✨ <strong><a target="_blank" href="https://www.thereactbootcamp.com">Introducing: The React Bootcamp</a></strong></p>
<p>You'll learn how to build every project in this list through hours of step-by-step videos, plus the complete source code to make them your own.</p>
<p>The bootcamp features every resource to help you succeed with React:</p>
<ul>
<li>🎬 200+ in-depth videos</li>
<li>🕹️ 100+ hands-on React challenges</li>
<li>🛠️ 5+ impressive portfolio projects</li>
<li>📄 10+ essential React cheat sheets</li>
<li>🥾 A complete Next.js bootcamp</li>
<li>🖼️ A complete series of animated videos</li>
</ul>
<p>Click below to try the React Bootcamp for yourself.</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a>  </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The React Roadmap for 2024 – How to Learn React ]]>
                </title>
                <description>
                    <![CDATA[ In this guide, I'll break down a complete roadmap that will cover all the concepts, libraries, and tools to help you become a React developer in 2024. My goal is to show you the happy path in React, navigating you away from pitfalls so you can spend ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-react-roadmap-learn-react/</link>
                <guid isPermaLink="false">66d037ff871ae63f179f6bce</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Tue, 09 Jan 2024 18:57:12 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/01/react-roadmap-2024.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this guide, I'll break down a complete roadmap that will cover all the concepts, libraries, and tools to help you become a React developer in 2024.</p>
<p>My goal is to show you the happy path in React, navigating you away from pitfalls so you can spend your time on what really matters in React to help you reach your goals.</p>
<p>Here's the roadmap I would choose for any React developer, whether you're a total beginner or a more advanced one, to help you build amazing apps, get a job, and enjoy using React.</p>
<p>If you're interested in a step-by-step guide on how to learn React in 2024, <a target="_blank" href="https://www.freecodecamp.org/news/how-to-learn-react-step-by-step/">check out this article</a> that I've written. I recommend reading the two together.</p>
<h2 id="heading-heres-an-outline">Here's an Outline:</h2>
<ol>
<li><a class="post-section-overview" href="#heading-learn-core-react-concepts">Learn Core React Concepts</a></li>
<li><a class="post-section-overview" href="#heading-learn-core-hooks">Learn Core Hooks</a></li>
<li><a class="post-section-overview" href="#heading-intermediate-react-concepts">Intermediate React Concepts</a></li>
<li><a class="post-section-overview" href="#heading-create-react-apps-with-vite">Create React Apps with Vite</a></li>
<li><a class="post-section-overview" href="#heading-fetch-data-with-tanstack-query">Fetch Data with TanStack Query</a></li>
<li><a class="post-section-overview" href="#heading-manage-state-with-zustand">Manage State with Zustand</a></li>
<li><a class="post-section-overview" href="#heading-style-with-tailwindcss-and-radix">Style with TailwindCSS and Radix</a></li>
<li><a class="post-section-overview" href="#heading-add-routing-with-tanstack-router">Add Routing with TanStack Router</a></li>
<li><a class="post-section-overview" href="#heading-build-forms-with-react-hook-form">Build Forms with React Hook Form</a></li>
<li><a class="post-section-overview" href="#heading-full-stack-react-apps-with-nextjs">Full-Stack React Apps with Next.js</a></li>
</ol>
<h2 id="heading-learn-core-react-concepts">🧱 Learn Core React Concepts</h2>
<p>There are a number of core React concepts that are necessary to build just about any React application, no matter how simple or complex.</p>
<p>The biggest concept in React is arguably <strong>components</strong>. In 2024, almost every component you make will be a <strong>function component</strong>.</p>
<p>These components are composed of React <strong>elements</strong> and <strong>JSX</strong>. Understanding the behavior of JSX is essential, as well as passing data to components using props and knowing the difference between <strong>props and state.</strong> Finally, knowing how to conditionally render parts of the user interface with <strong>conditional rendering</strong> is also key.</p>
<p>⏳ Spend less time on:</p>
<ul>
<li>Class components, which are almost exclusively seen in older projects. Class components are no longer the default component type due to React Hooks, which are used only in function components.</li>
<li>Older patterns like render props and higher-order components aren't necessary to learn because they were used largely before React Hooks arrived in 2018.</li>
<li>Simple concepts such as list, keys, and events, which are not as difficult to grasp.</li>
</ul>
<h2 id="heading-learn-core-hooks">🎣 Learn Core Hooks</h2>
<p>After the core concepts of React, you have the built-in React Hooks. The most important and frequently used of which are <strong>useState</strong>, <strong>useEffect</strong>, <strong>useRef</strong>, and <strong>useContext</strong>.</p>
<p>To use these hooks, you're going to need to understand the basics of React state, how to perform a side effect with useEffect, and avoid the potential pitfalls of useEffect, such as infinite loops.</p>
<p>You'll need to also understand refs for the useRef hook. And the context API for useContext.</p>
<p>Again, these are what you're going to use probably 90% of the time. The other 10% or so might be custom hooks that you make in order to add unique functionality to your application.</p>
<p>⏳ Spend less time on:</p>
<ul>
<li>Hooks like useReducer, which won't be used that frequently in comparison to useContext.</li>
<li>Optimization hooks like useCallback and useMemo. These can be important at times, but you'll use them far less frequently.</li>
</ul>
<h2 id="heading-intermediate-react-concepts">🧠 Intermediate React Concepts</h2>
<p>To really master React, you need to have a solid grasp of some intermediate concepts.</p>
<p>Some of these intermediate concepts include:</p>
<ul>
<li>Understand what causes React to render</li>
<li>How to move business logic into reusable hooks</li>
<li>Basic patterns like "lifting state up"</li>
<li>How to use composition to avoid prop drilling and overusing context</li>
</ul>
<p>While the core concepts I mentioned are usually best understood by actively coding and making React projects, intermediate concepts require understanding how React works.</p>
<p>Fortunately, you can get all of that understanding through reading the all-new <a target="_blank" href="https://react.dev">React documentation</a>. There are a number of very helpful guides covering these intermediate and sometimes advanced concepts.</p>
<h2 id="heading-create-react-apps-with-vite">🛠️ Create React Apps with Vite</h2>
<p>What is both a positive and a negative of React is how unopinionated it is. React helps us to make single-page applications, but we often need to resort to third-party libraries to add essential functionality.</p>
<p>To create a new React app in 2024, I'd highly recommend using the CLI/build tool, <strong>Vite</strong>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/Screenshot-2024-01-09-at-12.42.58-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Create React apps with Vite</em></p>
<p>You can use a package manager like NPM and a single command to create a React application from scratch with all the tools that you need to run it in development and build it for production.</p>
<pre><code class="lang-bash">npm create vite@latest my-react-app -- --template react
</code></pre>
<p>Create React App is no longer recommended. It's not being as actively maintained and is far slower than Vite.</p>
<h2 id="heading-fetch-data-with-tanstack-query">🐕 Fetch Data with TanStack Query</h2>
<p>Data fetching out of the box in React applications is hard. Without a dedicated library, you need to resort to performing HTTP requests in the useEffect hook.</p>
<p>However, this requires adding a lot of additional boilerplate code to manage loading and error state, and it doesn't handle a lot of logic to prevent making unnecessary requests.</p>
<p>The go-to library I'd recommend for any React or Next.js application would be <strong>TanStack Query</strong> (previously known as React Query).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/Screenshot-2024-01-09-at-12.43.53-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Fetch data with TanStack Query</em></p>
<p>It provides simple hooks to not only request but also to "mutate" (update) data from an API endpoint.</p>
<p>It covers just about everything you could want out of a data-fetching library, including caching, deduping multiple requests, knowing when data is out of date. And can be customized exactly the way you'd like.</p>
<p>If you're looking for a good alternative, you can try SWR. It does not have as many features as TanStack Query but is another good lightweight option that makes data fetching with React much easier.</p>
<h2 id="heading-manage-state-with-zustand">🤹‍♂️ Manage State with Zustand</h2>
<p>State management libraries are a must in React applications when you get to a certain size project. The default state management library for React applications for a long time has been Redux, and has been improved with Redux Toolkit.</p>
<p>There are still thousands of companies using Redux even in 2024. However, the ecosystem has shifted towards easier state management solutions.</p>
<p>That allows you to describe your state as an object and write functions to update properties on that state object. The go-to state management library for the past couple of years for me has been <strong>Zustand</strong>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/Screenshot-2024-01-09-at-12.44.32-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Manage state with Zustand</em></p>
<p>It's a great small library that's very helpful – not just at managing state across any component using simple hooks, but it also provides very convenient features such as preventing unnecessary rerenders.</p>
<p>There are many good alternatives to Zustand such as Recoil and Jotai, both of which share a similar API to Zustand.</p>
<h2 id="heading-style-with-tailwindcss-and-radix">✨ Style with TailwindCSS and Radix</h2>
<p>There are tons of styling options for React in the form of component libraries. These are premade sets of components, which not only offer a nice consistent design, but built-in functionality as well.</p>
<p>In past years, I would have recommended something like Material UI, but these component libraries can often be inflexible, hard to customize, and increase your bundle size greatly.</p>
<p>A better alternative for 2024 that many developers and businesses are moving towards is using a solution like <strong>Tailwind CSS</strong>. It just allows you to style your components with chainable, premade classes, in combination with a minimal component library, such as <strong>Radix</strong>.</p>
<p>Radix provides what are known as primitives. They allow you to make very functional components that your application needs such as dialogs, buttons, selects, tooltips, and just about anything you can think of, which can be styled any way you like.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/Screenshot-2024-01-09-at-12.45.07-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Style your apps with ShadCN UI</em></p>
<p><strong>ShadCN UI</strong> is a set of components that uses both TailwindCSS and Radix components and provides a good starting place for any application. You can also customize it more than a traditional component library.</p>
<p>I'd highly recommend using something like ShadCN UI for React projects that you use in 2024.</p>
<p>If you would like to use a component library instead, some good choices are Mantine, Chakra UI, and Material UI.</p>
<h2 id="heading-add-routing-with-tanstack-router">🪧 Add Routing with TanStack Router</h2>
<p><strong>React Router</strong> still remains the go-to router for most React applications you will build.</p>
<p>React Router has been around since virtually the beginning of React and continues to get significant updates with React Router 6. It covers just about any use case you can imagine, as you can see in their thorough documentation.</p>
<p>One important alternative, however, is <strong>TanStack Router</strong>. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/Screenshot-2024-01-09-at-12.45.50-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Add routing with TanStack Router</em></p>
<p>It's a brand new router for 2024 with a plethora of great features. It has type-safe navigation, built-in TypeScript support, nested routing, automatic route prefetching, and is designed for use with client-side data fetching libraries like TanStack Query and SWR.</p>
<p>If you're using TanStack Query, I'd highly recommend checking out TanStack Router for future React projects.</p>
<h2 id="heading-build-forms-with-react-hook-form">📑 Build Forms with React Hook Form</h2>
<p>Form libraries are not always necessary when building React apps. But if you need form validation, a highly customizable and straightforward choice is <strong>React Hook Form</strong>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/Screenshot-2024-01-09-at-12.46.53-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Form Validation with React Hook Form</em></p>
<p>With the built-in <code>useForm</code> hook, it makes it very easy to customize the input validation and the error messages.</p>
<p>What's great about React Hook Form is that there's very little code to add to your components. Most of it is abstracted in the useForm hook itself.</p>
<p>Some other reliable alternatives that might include a bit more code to setup are Formik and Final Form.</p>
<h2 id="heading-full-stack-react-apps-with-nextjs">🥞 Full-Stack React Apps with Next.js</h2>
<p>Perhaps the most important choice here when choosing a way to build a React project is the full-stack React framework.</p>
<p>These frameworks allow you to build not only the React client that users interact with, but also the server-side, where you can create APIs, add authentication, and so on.</p>
<p>The most popular React framework is <strong>Next.js</strong> and for good reason. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/Screenshot-2024-01-09-at-12.47.25-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Build full-stack apps with Next.js</em></p>
<p>Next.js 13 gave us server components, which allow us to run our React code on the server. This reduces the amount of JavaScript sent to our client, making for an overall better and faster user experience.</p>
<p>This also allows us to fetch data on the server, and include that data in our React component on its initial render. That means that we can avoid a lot of loading spinners, but still give our applications a single-page app-like experience.</p>
<p>The downside of Next.js is that it does come with a lot of patterns that might seem to conflict with the core concepts of React. But it's done with the intention of making your life easier as a React developer and building faster.</p>
<p>A good alternative to Next.js is <strong>Remix</strong>, which will soon be adopting server components.</p>
<h2 id="heading-become-a-professional-react-developer">🏆 Become a Professional React Developer</h2>
<p>Looking for the ultimate resource to learn React from start to finish?</p>
<p>✨ <strong><a target="_blank" href="https://www.thereactbootcamp.com">Introducing: The React Bootcamp</a></strong></p>
<p>The bootcamp features every resource to help you succeed with React:</p>
<ul>
<li>🎬 200+ in-depth videos</li>
<li>🕹️ 100+ hands-on React challenges</li>
<li>🛠️ 5+ impressive portfolio projects</li>
<li>📄 10+ essential React cheatsheets</li>
<li>🥾 A complete Next.js bootcamp</li>
<li>🖼️ A complete series of animated videos</li>
</ul>
<p>Click below to try the React Bootcamp for yourself.</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a><br><em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Learn React in 2024 – A Step-by-Step Guide ]]>
                </title>
                <description>
                    <![CDATA[ There's never been a better time to learn React than in 2024. In this comprehensive guide, I'll show you how I would go from knowing nothing about React to becoming a job-ready, junior React developer in 3 to 6 months. Keep in mind that becoming a sk... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-learn-react-step-by-step/</link>
                <guid isPermaLink="false">66d03787c1024fe75b758f4b</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Thu, 04 Jan 2024 21:48:22 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/01/learn-react-2024-4.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>There's never been a better time to learn React than in 2024.</p>
<p>In this comprehensive guide, I'll show you how I would go from knowing nothing about React to becoming a job-ready, junior React developer in 3 to 6 months.</p>
<p>Keep in mind that becoming a skilled developer is not a race. This is just the path I personally would choose to learn React from front to back as quickly and efficiently as possible.</p>
<p>This guide assumes that you have about 3-4 hours of undistracted time a day to dedicate to learning and practicing React. Feel free to adjust this guide to your particular circumstances and goals.</p>
<h2 id="heading-weeks-1-2-explore-the-new-react-docs">📖 Weeks 1-2: Explore the New React Docs</h2>
<p>If you're just getting started with React, the ideal resource throughout your journey is not a course or a book. It's the entirely free React documentation at <a target="_blank" href="https://react.dev">react.dev</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/Screenshot-2024-01-03-at-10.25.59-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>A sample page from the new React documentation</em></p>
<p>The React docs were rewritten in 2023. They are the official source for all things React, whether it's simple or complex topics.</p>
<p>Not only are the React docs a great way to become familiar with React, but it's also the most complete resource online to learn React from front to back.</p>
<p><strong>What To Do:</strong></p>
<ul>
<li>Try to read (and understand) the first 10 articles of the React docs.</li>
<li>Get familiar with the core React concepts: elements, components, JSX, passing data with props, rendering, and lists.</li>
</ul>
<p>If you encounter any especially difficult concepts, try asking ChatGPT for a simpler explanation.</p>
<p>The new React docs also include interactive code sandboxes, meaning you can play with the React code in their examples within the browser.</p>
<h2 id="heading-do-i-need-to-learn-javascript-first">🤔 Do I Need to Learn JavaScript First?</h2>
<p>You might be asking whether you need to fully learn JavaScript before you dive into React.</p>
<p>In 2024, I would personally say, <strong>no, you don't really need to.</strong></p>
<p>There are just a handful of JavaScript basics that you're going to need to utilize in any React app.</p>
<p>These include simple data types like strings, numbers, and booleans, as well as complex ones like objects and arrays, plus functions and asynchronous operations with promises. That's about it. <a target="_blank" href="https://www.freecodecamp.org/news/javascript-concepts-you-should-know-before-learning-react/">Here's an overview</a> of some of those concepts to know before diving into React.</p>
<p>Everything else can be learned as you encounter it. So no, you don't have to spend months learning JavaScript in its entirety before you dive into React.</p>
<h2 id="heading-week-3-run-a-react-project-on-your-computer">💻 Week 3: Run a React Project on Your Computer</h2>
<p>At this point, you need to do one crucial thing before building a React app.</p>
<p>You simply need to learn how to create a React project from scratch and run the project in development on your computer. That's it.</p>
<p><strong>What To Do:</strong></p>
<ul>
<li>Set aside a week to learn the entire process of creating, installing, and running a React project on your local machine.</li>
<li>The React documentation <a target="_blank" href="https://react.dev/learn/installation">has a complete guide</a> for this that you can dig into.</li>
</ul>
<p>It takes some time to get used to this process, but this is important because you will primarily be working here: out of a React project folder on your computer.</p>
<p>Spend some time setting up and getting comfortable with your code editor, which is likely going to be <strong>Visual Studio Code</strong>. Then see how to create a React project using <strong>Vite</strong>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/Screenshot-2024-01-03-at-10.27.10-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Visual Studio Code: the most popular React code editor</em></p>
<p>There are many ways to create React projects. But, I would highly recommend using Vite instead of Create React App. CRA is now outdated in 2024, and at this point, you shouldn't be creating projects with Next.js.</p>
<p>Finally, you want to get comfortable opening and running basic commands in your terminal, whether it's the integrated terminal in Visual Studio Code or your computer's terminal or command line.</p>
<p>If you have extra time, take a look at how to use Git and GitHub to see how to push any changes you make to your code. It's essential to keep track of these changes using a version control system like Git when you're working with a team.</p>
<p>If you have trouble with this step, remember that you can also create and code React apps in your browser using tools like <strong>CodeSandbox</strong> or <strong>StackBlitz</strong>. Not every <strong>project</strong> needs to be created as a folder on your computer.</p>
<h2 id="heading-weeks-4-6-build-static-react-projects">🧱 Weeks 4-6: Build Static React Projects</h2>
<p>Now that you have a basic grasp of what React is and how it can be used to build user interfaces, start building simple ones.</p>
<p>Before you start making fully functional applications, you need to focus on building the shell of it using React elements, components, and CSS for styling.</p>
<p><strong>What To Do:</strong></p>
<ul>
<li>Take a look at websites you use every day and see if you can build a part of it (a button, a navbar, a hero section, and so on)</li>
<li>It doesn't have to be a complete page – just start with a simple part. Write it as a separate component.</li>
<li>Recreate the component so that it looks close to the original in appearance (with the help of CSS).</li>
<li>As you feel more confident, try putting these components together into a more complete user interface.</li>
</ul>
<p>You can follow this process using simple React elements. You'll learn how to take those elements and break them into components so that they can be reused. After that, you can try to make it dynamic using data passed with props.</p>
<p>At this stage, I'd highly recommend getting comfortable with using CSS in React. You can use a simple stylesheet or something like <strong>Tailwind CSS</strong>, which is very popular.</p>
<p>Try not to use a component library because there is ultimately no way of avoiding CSS as a frontend developer. You need it to create attractive interfaces.</p>
<p>This stage of building static pages with React is also a good chance to learn the basics of <strong><a target="_blank" href="https://www.freecodecamp.org/news/semantic-html-alternatives-to-using-divs/">semantic HTML</a></strong>. If you don't know what that is, there are plenty of articles that will show you how to properly structure your HTML tags so that it's not an confusing pyramid of divs.</p>
<h2 id="heading-weeks-7-10-build-dynamic-react-projects">🛠️ Weeks 7-10: Build Dynamic React Projects</h2>
<p>After making static React projects, your goal is to make small, but functional React projects that perform a simple task.</p>
<p><strong>What To Do:</strong></p>
<ul>
<li>Try to make 10+ mini dynamic apps that perform a simple task using state and events.</li>
<li>They should be small, and take no longer than a day to make, such as a calculator, a video player, a todo list, an image carousel, a quote generator, and so on.</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/Screenshot-2024-01-03-at-10.28.23-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>An example intermediate React project: a shopping list app</em></p>
<p>What makes these projects intermediate exactly? In short, these projects should function more like real-world applications as compared to the basic, static ones. They should take user input, meaning handle events and manage data with React state.</p>
<p>You should make projects that use <strong>side effects</strong> as well. This usually involves requesting data from an external data source with the <strong>Fetch API</strong>.</p>
<p>During this stage, you should become comfortable working with the <strong>basic React hooks</strong>: useState, useEffect, and at times useRef, useContext, and maybe useReducer.</p>
<p>Don't worry too much about performance-related hooks like useCallback and useMemo. These should be used sparingly.</p>
<p>Try to build as many mini apps as you can (I would recommend at least 10), but don't spend more than a day at the most building any particular project. Build one, or if you can't, move on to the next one.</p>
<p>If you need any ideas, <a target="_blank" href="https://www.freecodecamp.org/news/react-projects-for-beginners-easy-ideas-with-code/">I have a complete article</a> that shows you a ton of React beginner projects that you can do within a day.</p>
<p>This period of time is very important for getting comfortable with using React and writing React-specific code as compared to just plain HTML (technically JSX) and CSS.</p>
<h2 id="heading-weeks-11-14-build-your-developer-portfolio">🧑‍💻 Weeks 11-14: Build Your Developer Portfolio</h2>
<p>This final stage of building projects should come after you feel that most intermediate projects have become a little too simple.</p>
<p>When you start feeling confident in building mini React projects, that's a sign that it's a good time to push yourself towards more advanced projects.</p>
<p><strong>What To Do:</strong></p>
<ul>
<li>Pick a larger, much more ambitious React project that you really want to make over the course of a longer period of time (like a month)</li>
<li>Highlight this project on your developer portfolio and describe what skills and tools you used to build it.</li>
</ul>
<p>An advanced project might be a mini clone of a larger application such as a YouTube clone where users can sign in, upload videos, and share them with friends.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/youtube-3-4.png" alt="Image" width="600" height="400" loading="lazy">
<em>An example portfolio project: a mini YouTube clone</em></p>
<p>Keep in mind that React is used to build major applications that you use every single day, like TikTok, Twitch, Hulu, Notion, and more. So think big when you are picking what portfolio projects to make.</p>
<p>These more advanced projects should take a much longer period of time, and that's a good thing. They should be a <strong>passion project</strong> – something that you really are interested in building with React, and excites you to make.</p>
<p>Along the way, you're going to be learning a lot of things that you didn't know before. You're going to need to research (for example, in our YouTube sample project):</p>
<ul>
<li>How to upload media with React</li>
<li>How to authenticate users using some kind of authentication service, whether free or paid</li>
<li>What library is best for playing videos in a React project</li>
</ul>
<p>All on top of many smaller decisions that you'll figure out along way.</p>
<p>This last stage should really challenge you as a developer. And what you ultimately build over the course of a month or more is a perfect addition to your developer portfolio.</p>
<p>Your developer portfolio should be one or more projects that represent your proficiency with React. It's going to show to your potential employer what you can bring to the job.</p>
<p>Once you've got a functioning project that you're proud of, you feel like you understand core React concepts pretty well, and you know how to problem-solve while coding, you should be in a good position to start applying for junior developer positions with React.</p>
<h2 id="heading-become-a-professional-react-developer">🏆 Become a Professional React Developer</h2>
<p>Looking for the ultimate resource to learn React from start to finish?</p>
<p>✨ <strong><a target="_blank" href="https://www.thereactbootcamp.com">Introducing: The React Bootcamp</a></strong></p>
<p>The bootcamp features every resource you need to succeed with React, including:</p>
<ul>
<li>🎬 200+ in-depth videos</li>
<li>🕹️ 100+ hands-on React challenges</li>
<li>🛠️ 5+ real-world portfolio projects</li>
<li>📚 10+ essential React cheatsheets</li>
<li>🥾 A complete Next.js bootcamp</li>
<li>🖼️ A complete series of animated videos</li>
</ul>
<p>Click below to try the React Bootcamp for yourself!</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a><br><em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn React Props – The Animated Guide ]]>
                </title>
                <description>
                    <![CDATA[ Props are a common stumbling block when moving from JavaScript to React. In reality, using props in React components is almost identical to using arguments in plain JavaScript functions. Let's take a quick look at what props are in React through some... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/react-props-animated-guide/</link>
                <guid isPermaLink="false">66d037dc2b211a17e00e3704</guid>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Sun, 17 Dec 2023 21:38:23 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/12/react-props-animated.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Props are a common stumbling block when moving from JavaScript to React.</p>
<p>In reality, using props in React components is almost identical to using arguments in plain JavaScript functions.</p>
<p>Let's take a quick look at what props are in React through some helpful animations. These will help you visualize how props function and how you can use them in your React projects.</p>
<h2 id="heading-how-to-pass-data-to-a-javascript-function">How to Pass Data to a JavaScript Function</h2>
<p>The following JavaScript function is broken. What will happen if you try to use it?</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sum</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> a + b;
} 

sum(); <span class="hljs-comment">// Reference Error: a is not defined</span>
</code></pre>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/quaqsusb34cn96j9etvh.gif" alt="1" width="1920" height="1080" loading="lazy">
<em>When sum function is called, it throws a Reference Error: a is not defined</em></p>
<p>If you call this function, you’re going to get a Reference Error which says, "a is not defined".</p>
<p>This makes sense – the <code>sum</code> function is using two values, <code>a</code> and <code>b</code>, but has no idea what they are.</p>
<p>To fix it, we need to add <code>a</code> and <code>b</code> as parameters and pass two numbers as arguments.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sum</span>(<span class="hljs-params">a, b</span>) </span>{
  <span class="hljs-keyword">return</span> a + b;   
}

sum(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>); <span class="hljs-comment">// 4</span>
</code></pre>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ad157f12fb7vqs2ndg5.gif" alt="2" width="1920" height="1080" loading="lazy">
<em>Fix the sum function by passing values to both arguments a and b</em></p>
<p>That’s how you pass data to a JavaScript function, but what about a React component?</p>
<h2 id="heading-how-to-pass-data-to-a-react-component">How to Pass Data to a React Component</h2>
<p>A React component looks a lot like a plain JavaScript function. But unlike a JS function, it returns and renders React elements, such as a button.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Button</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Click me<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>;   
}
</code></pre>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cbqcu6zf3qwpufqpbp8c.gif" alt="3" width="1920" height="1080" loading="lazy">
<em>React component, Button, that renders a button element</em></p>
<p>To call a React component and have it display those elements, we use it as if it was a custom HTML element, but written in JavaScript.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Button</span> /&gt;</span></span>;   
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Button</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Click me<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>;   
}
</code></pre>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xmcqn8e44iiid275os5r.gif" alt="4" width="1920" height="1080" loading="lazy">
<em>Button component is used in another component, App</em></p>
<p>But how do we pass data to functions when they are called like this?</p>
<p>Using this HTML-like syntax, we can pass it any data we like as if it was a custom HTML attribute.</p>
<p>For example, if we wanted to add our own custom text to our button, we could add a text attribute and set its value equal to some string.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Button</span> <span class="hljs-attr">text</span>=<span class="hljs-string">"⭐️"</span> /&gt;</span></span>;   
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Button</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Click me<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>;   
}
</code></pre>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8qf1wtif6bfamoz7cb8j.gif" alt="5" width="1920" height="1080" loading="lazy">
<em>"text" prop is added to the Button component, with value ⭐️</em></p>
<p>In the world of React, this custom attribute is what is known as a "prop". </p>
<p>We can add as many props to our components as we like. They can be any JavaScript data type.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Button</span> <span class="hljs-attr">text</span>=<span class="hljs-string">"⭐️"</span> <span class="hljs-attr">color</span>=<span class="hljs-string">"green"</span> /&gt;</span></span>;   
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Button</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Click me<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>;   
}
</code></pre>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98vxu9888zplkonokr3q.gif" alt="6" width="1920" height="1080" loading="lazy">
<em>prop named "color" (with the value "green") is added to the Button component</em></p>
<p>If we want to use the props we've passed down to our component, you might think that each one is passed as a separate argument.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jsymr9ltwjl9kqqcxbpk.gif" alt="7" width="1920" height="1080" loading="lazy">
<em>Passed props are not provided as separate arguments to a component</em></p>
<p>But that’s not the case. Unlike a regular JavaScript function, all of these props are collected into one value, which is itself an object.</p>
<p>This single parameter is referred to and named "props”.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h2vkphx043s8x0mewa58.gif" alt="8" width="1920" height="1080" loading="lazy">
<em>All props that are passed to a component become properties on a single object within that component's parameters</em></p>
<p>It can be named anything, but the convention is to call this parameter "props" because that's what it contains – all of the values that are passed down to this component.</p>
<p>Another reason it makes sense to call these values “props” is because what we've passed down are turned into properties on an object.</p>
<p>Once we’ve passed down the data that we like to our component, they can be used inside that component with curly braces.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Button</span> <span class="hljs-attr">text</span>=<span class="hljs-string">"⭐️"</span> <span class="hljs-attr">color</span>=<span class="hljs-string">"green"</span> /&gt;</span></span>;   
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Button</span>(<span class="hljs-params">props</span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">background:</span> <span class="hljs-attr">props.color</span> }}&gt;</span>
     {props.text}
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
  );
}
</code></pre>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n5smudo77dekbv641msq.gif" alt="9" width="1920" height="1080" loading="lazy">
<em>The "color" and "text" props are used as properties within the Button component</em></p>
<p>And a neat pattern to use if your components are small, is to destructure the props object.</p>
<p>By adding a set of curly braces in your parameters, you can use destructure props into individual variables that you can use directly.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Button</span> <span class="hljs-attr">text</span>=<span class="hljs-string">"⭐️"</span> <span class="hljs-attr">color</span>=<span class="hljs-string">"green"</span> /&gt;</span></span>;   
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Button</span>(<span class="hljs-params">{ color, text }</span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">background:</span> <span class="hljs-attr">color</span> }}&gt;</span>
     {text}
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
  );
}
</code></pre>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1c19ivyfpnfnpepejkjp.gif" alt="10" width="1920" height="1080" loading="lazy">
<em>Props are destructured as individual variables within the Button component, "color" and "text"</em></p>
<h2 id="heading-become-a-professional-react-developer">🏆 Become a Professional React Developer</h2>
<p>React is hard. You shouldn't have to figure it out yourself.</p>
<p>I've put everything I know about React into a single course, to help you reach your goals in record time:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><strong>Introducing: The React Bootcamp</strong></a></p>
<p>It features over 100 hands-on challenges, real-world projects, and a complete series of animations to help you finally understand how React works.</p>
<p><strong>It’s the one course I wish I had when I started learning React.</strong></p>
<p>Click below to try the React Bootcamp for yourself:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a>
<em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Python Variables – The Complete Beginner's Guide ]]>
                </title>
                <description>
                    <![CDATA[ Variables are an essential part of Python. They allow us to easily store, manipulate, and reference data throughout our projects. This article will give you all the understanding of Python variables you need to use them effectively in your projects. ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/python-variables/</link>
                <guid isPermaLink="false">66d037ae2b211a17e00e36f3</guid>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ variables ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Wed, 22 Mar 2023 18:30:52 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/03/mugshotbot.com_customize_color-yellow-image-9820e115-mode-light-pattern-texture-theme-two_up-url-https___gifcoins.io.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Variables are an essential part of Python. They allow us to easily store, manipulate, and reference data throughout our projects.</p>
<p>This article will give you all the understanding of Python variables you need to use them effectively in your projects.</p>
<p>If you want the most convenient way to review all the topics covered here, I've put together a helpful cheatsheet for you right here:</p>
<p><strong><a target="_blank" href="https://reedbarger.com/resources/python-variables">Download the</a></strong> Python variables cheatsheet (it takes 5 seconds).</p>
<h2 id="heading-what-is-a-variable-in-python">What is a Variable in Python?</h2>
<p>So what are variables and why do we need them?</p>
<p>Variables are essential for holding onto and referencing values throughout our application. By storing a value into a variable, you can reuse it as many times and in whatever way you like throughout your project. </p>
<p>You can think of variables as boxes with labels, where the label represents the variable name and the content of the box is the value that the variable holds.</p>
<p>In Python, variables are created the moment you give or <strong>assign</strong> a value to them.</p>
<h2 id="heading-how-do-i-assign-a-value-to-a-variable">How Do I Assign a Value to a Variable?</h2>
<p>Assigning a value to a variable in Python is an easy process. </p>
<p>You simply use the equal sign <code>=</code> as an assignment operator, followed by the value you want to assign to the variable. Here's an example:</p>
<pre><code class="lang-python">country = <span class="hljs-string">"United States"</span>
year_founded = <span class="hljs-number">1776</span>
</code></pre>
<p>In this example, we've created two variables: <code>country</code> and <code>year_founded.</code> We've assigned the string value "United States" to the <code>country</code> variable and integer value 1776 to the <code>year_founded</code> variable.</p>
<p>There are two things to note in this example:</p>
<ol>
<li>Variables in Python are <strong>case-sensitive</strong>. In other words, watch your casing when creating variables, because <code>Year_Founded</code> will be a different variable than <code>year_founded</code> even though they include the same letters</li>
<li>Variable names that use multiple words in Python should be separated with an underscore <code>_</code><em>.</em> For example, a variable named "site name" should be written as "site<em>name"</em>._ This convention is called <strong>snake case</strong> (very fitting for the "Python" language).</li>
</ol>
<h2 id="heading-how-should-i-name-my-python-variables">How Should I Name My Python Variables?</h2>
<p>There are some rules to follow when naming Python variables. </p>
<p>Some of these are hard rules that must be followed, otherwise your program will not work, while others are known as <strong>conventions</strong>. This means, they are more like suggestions.</p>
<h3 id="heading-variable-naming-rules">Variable naming rules</h3>
<ol>
<li>Variable names must start with a letter or an underscore <code>_</code> character.</li>
<li>Variable names can only contain letters, numbers, and underscores.</li>
<li>Variable names cannot contain spaces or special characters.</li>
</ol>
<pre><code class="lang-python">user_age = <span class="hljs-number">20</span> <span class="hljs-comment"># valid</span>

website = <span class="hljs-string">'https://freecodecamp.org'</span> <span class="hljs-comment"># valid</span>

<span class="hljs-number">1</span>password = <span class="hljs-literal">True</span> <span class="hljs-comment"># invalid</span>
</code></pre>
<h3 id="heading-variable-naming-conventions">Variable naming conventions</h3>
<ol>
<li>Variable names should be descriptive and not too short or too long.</li>
<li>Use lowercase letters and underscores to separate words in variable names (known as "snake_case").</li>
</ol>
<h2 id="heading-what-data-types-can-python-variables-hold">What Data Types Can Python Variables Hold?</h2>
<p>One of the best features of Python is its flexibility when it comes to handling various data types.</p>
<p>Python variables can hold various data types, including integers, floats, strings, booleans, tuples and lists:</p>
<p><strong>Integers</strong> are whole numbers, both positive and negative.</p>
<pre><code class="lang-python">answer = <span class="hljs-number">42</span>
</code></pre>
<p><strong>Floats</strong> are real numbers or numbers with a decimal point.</p>
<pre><code class="lang-python">weight = <span class="hljs-number">34.592</span>
</code></pre>
<p><strong>Strings</strong> are sequences of characters, namely words or sentences.</p>
<pre><code class="lang-python">message = <span class="hljs-string">"Hello Python"</span>
</code></pre>
<p><strong>Booleans</strong> are True or False values.</p>
<pre><code class="lang-python">is_authenticated = <span class="hljs-literal">True</span>
</code></pre>
<p><strong>Lists</strong> are ordered, mutable collections of values.</p>
<pre><code class="lang-python">fruits = [<span class="hljs-string">'apple'</span>, <span class="hljs-string">'banana'</span>, <span class="hljs-string">'cherry'</span>]
</code></pre>
<p><strong>Tuples</strong> are ordered, immutable collections of values.</p>
<pre><code class="lang-python">point = (<span class="hljs-number">3</span>, <span class="hljs-number">4</span>)
</code></pre>
<p>There are more data types in Python, but these are the most common ones you will encounter while working with Python variables.</p>
<h2 id="heading-python-is-dynamically-typed">Python is Dynamically Typed</h2>
<p>Python is what is known as a <strong>dynamically-typed</strong> language. This means that the type of a variable can change during the execution of a program. </p>
<p>Another feature of dynamic typing is that it is not necessary to manually declare the type of each variable, unlike other programming languages such as Java.</p>
<p>You can use the <code>type()</code> function to determine the type of a variable. For instance:</p>
<pre><code class="lang-python">print(type(answer))  <span class="hljs-comment"># Output: &lt;class 'int'&gt;</span>
print(type(message))  <span class="hljs-comment"># Output: &lt;class 'str'&gt;</span>
</code></pre>
<h2 id="heading-what-operations-can-be-performed">What Operations Can Be Performed?</h2>
<p>Variables can be used in various operations, which allows us to transform them mathematically (if they are numbers), change their string values through operations like concatenation, and compare values using equality operators.</p>
<h3 id="heading-mathematic-operations">Mathematic Operations</h3>
<p>It's possible to perform basic mathematic operations with variables, such as addition, subtraction, multiplication, and division:</p>
<pre><code class="lang-python"><span class="hljs-comment"># Arithmetic operations</span>
a = <span class="hljs-number">10</span>
b = <span class="hljs-number">5</span>

sum = a + b
difference = a - b
product = a * b
quotient = a / b

print(sum, difference, product, quotient)  <span class="hljs-comment"># Output: 15 5 50 2.0</span>
</code></pre>
<p>It's also possible to find the remainder of a division operation by using the modulus <code>%</code> operator as well as create exponents using the <code>**</code> syntax:</p>
<pre><code class="lang-python"><span class="hljs-comment"># Modulus operation</span>
remainder = a % b
print(remainder)  <span class="hljs-comment"># Output: 0</span>

<span class="hljs-comment"># Exponentiation</span>
power = a ** b
print(power)  <span class="hljs-comment"># Output: 100000</span>
</code></pre>
<h3 id="heading-string-operators">String operators</h3>
<p>Strings can be added to one another or <strong>concatenated</strong> using the <code>+</code> operator.</p>
<pre><code class="lang-python"><span class="hljs-comment"># String concatenation</span>
first_name = <span class="hljs-string">"Guido"</span>
last_name = <span class="hljs-string">"van Rossum"</span>
full_name = first_name + <span class="hljs-string">" "</span> + last_name
print(full_name)  <span class="hljs-comment"># Output: Guido van Rossum</span>
</code></pre>
<h3 id="heading-equality-comparisons">Equality comparisons</h3>
<p>Values can also be compared in Python using the <code>&lt;</code>, <code>&gt;</code>, <code>==</code>, and <code>!=</code> operators. </p>
<p>These operators, respectively, compare whether values are less than, greater than, equal to, or not equal to each other.</p>
<pre><code class="lang-python"><span class="hljs-comment"># Comparison operations</span>
x = <span class="hljs-number">15</span>
y = <span class="hljs-number">20</span>

print(x &lt; y)  <span class="hljs-comment"># Output: True</span>
print(x &gt; y)  <span class="hljs-comment"># Output: False</span>
print(x == y)  <span class="hljs-comment"># Output: False</span>
print(x != y)  <span class="hljs-comment"># Output: True</span>
</code></pre>
<p>Finally, note that when performing operations with variables, you need to ensure that the types of the variables are compatible with each other. </p>
<p>For example, you cannot directly add a string and an integer. You would need to convert one of the variables to a compatible type using a function like <code>str()</code> or <code>[int()](https://www.freecodecamp.org/news/python-string-to-int-convert-a-string-example/)</code>. </p>
<h2 id="heading-variable-scope">Variable Scope</h2>
<p>The scope of a variable refers to the parts of a program where the variable can be accessed and modified. In Python, there are two main types of variable scope:</p>
<p><strong>Global scope</strong>: Variables defined outside of any function or class have a global scope. They can be accessed and modified throughout the program, including within functions and classes.</p>
<pre><code class="lang-python">global_var = <span class="hljs-string">"I am a global variable"</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">access_global_var</span>():</span>
    print(global_var)

access_global_var()  <span class="hljs-comment"># Output: I am a global variable</span>
</code></pre>
<p><strong>Local scope</strong>: Variables defined within a function or class have a local scope. They can only be accessed and modified within that function or class.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">function_with_local_var</span>():</span>
    local_var = <span class="hljs-string">"I am a local variable"</span>
    print(local_var)

function_with_local_var()  <span class="hljs-comment"># Output: I am a local variable</span>
print(local_var)  <span class="hljs-comment"># Error: NameError: name 'local_var' is not defined</span>
</code></pre>
<p>In this example, attempting to access <code>local_var</code> outside of the <code>function_with_local_var</code> function results in a <code>NameError</code>, as the variable is not defined in the global scope.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Don't be afraid to experiment with different types of variables, operations, and scopes to truly grasp their importance and functionality. The more you work with Python variables, the more confident you'll become in applying these concepts.</p>
<p>Finally, if you want to fully learn all of these concepts, I've put together for you a super helpful cheatsheet that summarizes everything we've covered here.</p>
<p>Just click the link below to grab it for free. Enjoy!</p>
<p><strong><a target="_blank" href="https://reedbarger.com/resources/python-variables">Download the</a></strong> Python variables cheatsheet</p>
<h2 id="heading-become-a-professional-react-developer">Become a Professional React Developer</h2>
<p>React is hard. You shouldn't have to figure it out yourself.</p>
<p>I've put everything I know about React into a single course, to help you reach your goals in record time:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><strong>Introducing: The React Bootcamp</strong></a></p>
<p><strong>It’s the one course I wish I had when I started learning React.</strong></p>
<p>Click below to try the React Bootcamp for yourself:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a>
<em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ JavaScript One-Liners to Use in Every Project ]]>
                </title>
                <description>
                    <![CDATA[ JavaScript is a powerful language that can do a lot with very little code. In some cases, the amount of code you need to write doesn't exceed more than a single line, which is why they are known as one-liners. Let's go through 10 essential one liners... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/javascript-one-liners-to-use-in-every-project/</link>
                <guid isPermaLink="false">66d0379cccf811d3117aeee1</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Fri, 10 Mar 2023 21:18:03 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/javascript-one-liner.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>JavaScript is a powerful language that can do a lot with very little code.</p>
<p>In some cases, the amount of code you need to write doesn't exceed more than a single line, which is why they are known as one-liners.</p>
<p>Let's go through 10 essential one liners worth using in virtually every JavaScript project you create. </p>
<h2 id="heading-1-how-to-capitalize-text">1. How to Capitalize Text</h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> capitalize = <span class="hljs-function">(<span class="hljs-params">str</span>) =&gt;</span> <span class="hljs-string">`<span class="hljs-subst">${str.charAt(<span class="hljs-number">0</span>).toUpperCase()}</span><span class="hljs-subst">${str.slice(<span class="hljs-number">1</span>)}</span>`</span>;
</code></pre>
<p>Capitalizing strings is not a built-in feature of JavaScript. </p>
<p>To fix this, we can make a <code>capitalize</code> function which accepts some text and makes the first letter uppercase, then appends the rest of the string.</p>
<p>This one-liner is useful for just about every kind of text you want to capitalize. I use it most frequently with displaying users' names.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> name = <span class="hljs-string">"robert"</span>;

capitalize(name) <span class="hljs-comment">// "Robert";</span>
</code></pre>
<h2 id="heading-2-how-to-calculate-percent">2. How to Calculate Percent</h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> calculatePercent = <span class="hljs-function">(<span class="hljs-params">value, total</span>) =&gt;</span> <span class="hljs-built_in">Math</span>.round((value / total) * <span class="hljs-number">100</span>)
</code></pre>
<p>Calculating a percent is pretty easy and just involves some simple math. It is an essential task if you want to display user progress, for example in incrementing a progress bar. </p>
<p><code>calculatePercent</code> accepts a certain amount, divides it by the total amount, then multiplies it by 100. Finally, we use <code>Math.round()</code> to round the result up to the nearest whole number.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> questionsCorrect = <span class="hljs-number">6</span>;
<span class="hljs-keyword">const</span> questionTotal = <span class="hljs-number">11</span>;

calculatePercent(questionsCorrect, questionsTotal); <span class="hljs-comment">// 55</span>
</code></pre>
<h2 id="heading-3-how-to-get-a-random-element">3. How to Get a Random Element</h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> getRandomItem = <span class="hljs-function">(<span class="hljs-params">items</span>) =&gt;</span>  items[<span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random() * items.length)];
</code></pre>
<p>Getting a random element and array is really nice when you want to make things unique for your user. </p>
<p>For example, you might want to show your users a congratulations message based on some action. But you probably don't want to show them the same one every time, because that would get repetitive and boring. </p>
<p><code>getRandomItem</code> uses the <code>Math.random()</code> function, which returns a decimal between 0 and 1. This is multiplied by the length of the array to select a random index, which can be used to select a random element.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> items = [<span class="hljs-string">"Nicely done!"</span>, <span class="hljs-string">"Good job!"</span>, <span class="hljs-string">"Good work!"</span>, <span class="hljs-string">"Correct!"</span>];

getRandomItem(items); <span class="hljs-comment">// "Good job!"</span>
</code></pre>
<h2 id="heading-4-how-to-remove-duplicate-elements">4. How to Remove Duplicate Elements</h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> removeDuplicates = <span class="hljs-function">(<span class="hljs-params">arr</span>) =&gt;</span> [...new <span class="hljs-built_in">Set</span>(arr)];
</code></pre>
<p>Removing duplicate values in an array is an essential task in JavaScript. </p>
<p>For example, you might be adding one user to another user's friends list, but you don't want that user to be added or displayed twice.</p>
<p>This <code>removeDuplicates</code> function leverages the <code>Set</code> constructor in JavaScript, which removes any duplicate (primitive) values by default. After that, we use the spread operator <code>...</code> to spread its values into a new array.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> friendList = [<span class="hljs-string">"Jeff"</span>, <span class="hljs-string">"Jane"</span>, <span class="hljs-string">"Jane"</span>, <span class="hljs-string">"Rob"</span>];

removeDuplicates(friendList); <span class="hljs-comment">// ['Jeff', 'Jane', 'Rob']</span>
</code></pre>
<h2 id="heading-5-how-to-sort-elements-by-certain-property">5. How to Sort Elements By Certain Property</h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> sortBy = <span class="hljs-function">(<span class="hljs-params">arr, key</span>) =&gt;</span> arr.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> a[key] &gt; b[key] ? <span class="hljs-number">1</span> : a[key] &lt; b[key] ? <span class="hljs-number">-1</span> : <span class="hljs-number">0</span>);
</code></pre>
<p>A common task when displaying data in JavaScript is to sort it based on some property. </p>
<p>This <code>sortBy</code> function uses the native sort method, compares the elements in the array based off of the provided key, and sorts the array in ascending order. </p>
<p>Where would this be helpful? If you're fetching data that is supposed to be in a certain position based off of a position key, <code>sortBy</code> will make sure that those elements are placed in the proper order. </p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> lessons = [{ <span class="hljs-attr">position</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">"Intro"</span> }, { <span class="hljs-attr">position</span>: <span class="hljs-number">0</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">"Basics"</span> }];

sortBy(lessons, <span class="hljs-string">'position'</span>); 

<span class="hljs-comment">// {position: 0, name: 'Basics'},</span>
<span class="hljs-comment">// {position: 1, name: 'Intro'}</span>
</code></pre>
<h2 id="heading-6-how-to-check-if-arraysobjects-are-equal">6. How to Check if Arrays/Objects are Equal</h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> isEqual = <span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> <span class="hljs-built_in">JSON</span>.stringify(a) === <span class="hljs-built_in">JSON</span>.stringify(b);
</code></pre>
<p>It's easy to check for equality with JavaScript primitives, like numbers and strings. </p>
<p>Checking for equality between arrays and objects is a bit harder, however. Fortunately, there's a neat trick you can use with <code>JSON.stringify</code> to convert arrays or objects into a JSON string. If all the elements match, <code>isEqual</code> will return a value of true.</p>
<p>This is very handy when you expect multiple inputs from a user, for example if they're answering a question and you want to compare it to the correct solution. </p>
<pre><code class="lang-js">isEqual([<span class="hljs-number">1</span>, <span class="hljs-string">'2'</span>], [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>]); <span class="hljs-comment">// false</span>
isEqual([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>], [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>]); <span class="hljs-comment">// true</span>
</code></pre>
<h2 id="heading-7-how-to-count-number-of-occurrences">7. How to Count Number of Occurrences</h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> countOccurrences = <span class="hljs-function">(<span class="hljs-params">arr, value</span>) =&gt;</span> arr.reduce(<span class="hljs-function">(<span class="hljs-params">a, v</span>) =&gt;</span> (v === value ? a + <span class="hljs-number">1</span> : a), <span class="hljs-number">0</span>);
</code></pre>
<p>Another helpful array-based one liner is to count the number of occurrences of an element in an array. It uses the <code>.reduce()</code> function. If the value is found in the array, it increments a counter by one. </p>
<p>One useful example might be a poll to determine what most people voted for. </p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> pollResponses = [<span class="hljs-string">"Yes"</span>, <span class="hljs-string">"Yes"</span>, <span class="hljs-string">"No"</span>];
<span class="hljs-keyword">const</span> response = <span class="hljs-string">"Yes"</span>;

countOccurrences(pollResponses, response); <span class="hljs-comment">// 2</span>
</code></pre>
<h2 id="heading-8-how-to-wait-for-a-certain-amount-of-time">8. How to Wait for a Certain Amount of Time</h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> wait = <span class="hljs-keyword">async</span> (milliseconds) =&gt; <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve</span>) =&gt;</span> <span class="hljs-built_in">setTimeout</span>(resolve, milliseconds));
</code></pre>
<p>In your application, you might want to wait for a certain period of time. For example, if you want to delay an animation or are waiting for an important operation for finish. </p>
<p>You can provide the <code>wait</code> function a certain amount of time to wait in milliseconds. Because it uses a promise, you can use the <code>then</code> callback or the <code>await</code> keyword to make sure it has finished. </p>
<pre><code class="lang-js">wait(<span class="hljs-number">2000</span>).then(<span class="hljs-function">() =&gt;</span> goToSignupPage());
</code></pre>
<h2 id="heading-9-how-to-use-the-pluck-property-from-array-of-objects">9. How to Use the Pluck Property from Array of Objects</h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> pluck = <span class="hljs-function">(<span class="hljs-params">objs, key</span>) =&gt;</span> objs.map(<span class="hljs-function">(<span class="hljs-params">obj</span>) =&gt;</span> obj[key]);
</code></pre>
<p>If you need to extract data from an array of objects and are not interested in getting all the data that is returned, use the <code>pluck</code> function. </p>
<p>It takes an array of objects and a property that each of the objects contains. The function maps over this array and returns an array with only the values of the property that we specified. </p>
<p>For example, if we have an array of user data, but we want to convert it just to an array of their names, <code>pluck</code> can do this.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> users = [{ <span class="hljs-attr">name</span>: <span class="hljs-string">"Abe"</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">45</span> }, { <span class="hljs-attr">name</span>: <span class="hljs-string">"Jennifer"</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">27</span> }];

pluck(users, <span class="hljs-string">'name'</span>); <span class="hljs-comment">// ['Abe', 'Jennifer']</span>
</code></pre>
<h2 id="heading-10-how-to-insert-an-element-at-a-certain-position">10. How to Insert an Element at a Certain Position</h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> insert = <span class="hljs-function">(<span class="hljs-params">arr, index, newItem</span>) =&gt;</span> [...arr.slice(<span class="hljs-number">0</span>, index), newItem, ...arr.slice(index)];
</code></pre>
<p>If we want to put an element in a precise location in an array, we can use this special <code>insert</code> function. </p>
<p>To use it, we just need to pass to <code>insert</code> the array we want to transform, the index where we want the element insert, and the element to insert.</p>
<p>This is a great function to use instead of <code>.splice()</code> because it does not mutate the original array. It creates a new array with the help of the slice method, by slicing the array into two parts around the specified index and then creates a new one.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> items = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];

<span class="hljs-comment">// insert the number 3 at index 2:</span>

insert(items, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>); <span class="hljs-comment">// [1, 2, 3, 4, 5]</span>
</code></pre>
<h2 id="heading-become-a-professional-react-developer">Become a Professional React Developer</h2>
<p>React is hard. You shouldn't have to figure it out yourself.</p>
<p>I've put everything I know about React into a single course, to help you reach your goals in record time:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><strong>Introducing: The React Bootcamp</strong></a></p>
<p><strong>It’s the one course I wish I had when I started learning React.</strong></p>
<p>Click below to try the React Bootcamp for yourself:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a>
<em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ React Projects for Beginners in 2023 – Fun Ideas with Code ]]>
                </title>
                <description>
                    <![CDATA[ You're ready to start making simple projects with React, but you don't know what to make. Where should you start? I have created seven unique and fun React projects for you to make, all of which will teach you essential React concepts that you need t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/react-projects-for-beginners-easy-ideas-with-code/</link>
                <guid isPermaLink="false">66d037d22b211a17e00e3700</guid>
                
                    <category>
                        <![CDATA[ projects ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Tue, 10 Jan 2023 17:53:44 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/7-react-projects-beginners.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>You're ready to start making simple projects with React, but you don't know what to make. Where should you start?</p>
<p>I have created seven unique and fun React projects for you to make, all of which will teach you essential React concepts that you need to know in 2023. </p>
<p>Unlike other recommended projects which require you going to use multiple third-party libraries, all of these projects only use the core React library. Each of them use the latest React version (18) and no CSS frameworks. </p>
<p>My goal in creating this guide is to show you that you don't need a ton of code and special libraries to start building cool things with React. </p>
<p>Let's get started!</p>
<h2 id="heading-1-image-carousel">1. Image Carousel</h2>
<p>The first React project on our list is an image slider or carousel. </p>
<h3 id="heading-final-result">Final result</h3>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codesandbox.io/embed/runtime-field-xp5sol" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodeSandbox embed" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" loading="lazy"></iframe></div>
<h3 id="heading-how-you-will-build-it">How you will build it</h3>
<p>Our carousel should allow the user to click the backwards or forwards button to go to the previous or next image. </p>
<p>The images will be stored in a simple array. We will see how to use state in order to store the current image. Then we will update that state to go to the previous or next image, according to the button the user pressed. </p>
<p>If the user has gone through all of the images, you will figure out how to start at the beginning of the array, to allow them to cycle through the images again. If you don't want to use images, you could also use text to make a testimonial carousel that cycles through reviews for a given product. </p>
<p>Finally, if you want to take your carousel to the next level, try adding a fun transition using CSS to animate the image as it changes.</p>
<h3 id="heading-react-concepts-you-will-learn">React concepts you will learn</h3>
<ul>
<li>useState (storing and updating state)</li>
<li>Conditionals (ternaries)</li>
<li>Lists, keys, and .map()</li>
</ul>
<h2 id="heading-2-faqaccordion">2. FAQ/Accordion</h2>
<p>Another common type of component which can utilizes state is an accordion component, which can both reveal and hide text.</p>
<h3 id="heading-final-result-1">Final result</h3>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codesandbox.io/embed/determined-hoover-22hclm" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodeSandbox embed" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" loading="lazy"></iframe></div>
<h3 id="heading-how-you-will-build-it-1">How you will build it</h3>
<p>You will learn how to toggle state to make sure that each accordion opens and closes after each button press. You will also learn simple conditionals such as the and (&amp;&amp;) operator that will only show the content of the accordion when the accordion state says it is open. </p>
<p>Finally, we will create an entire FAQ (frequently asked questions) section by displaying multiple accordion components. To do so, we will learn how to pass each accordion's data down into the component using props.</p>
<h3 id="heading-react-concepts-you-will-learn-1">React concepts you will learn</h3>
<ul>
<li>Toggling state with useState</li>
<li>Conditionals (&amp;&amp;)</li>
<li>Passing data to components via props</li>
<li>Displaying multiple components with <code>.map()</code></li>
</ul>
<h2 id="heading-3-quote-generator">3. Quote Generator</h2>
<p>Using external APIs and making HTTP requests are an essential part of any React application. To learn how to make HTTP requests in React, we will make a random quote generator.</p>
<h3 id="heading-final-result-2">Final result</h3>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codesandbox.io/embed/zen-diffie-x61ywc" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodeSandbox embed" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" loading="lazy"></iframe></div>
<h3 id="heading-how-you-will-build-it-2">How you will build it</h3>
<p>Our quote generator will need to use the useEffect hook to perform a "side effect" to fetch the quotes from an external API. After fetching our quotes, we will put them in our local app state, which we will call <code>quotes</code>. </p>
<p>We'll then take that array of quotes and use a function to select a random item within that array. Then we'll put it in another state variable called just <code>quote</code>, which can then be displayed to our user. </p>
<p>We also want to add a "New Quote" button above each quote that will perform the same operation – get a new random quote from our <code>quotes</code> array and put it in <code>quote</code>.</p>
<p>Finally, the quote isn't loaded in state. So we'll make sure to use the optional chaining operator (?) to safely check our object before we attempt to get a value from that quote in state to make sure our app doesn't throw an error.</p>
<h3 id="heading-react-concepts-you-will-learn-2">React concepts you will learn</h3>
<ul>
<li>useEffect (to perform side effects)</li>
<li>HTTP requests with Fetch API</li>
<li>Conditional chaining operator (?)</li>
</ul>
<h2 id="heading-4-shopping-list">4. Shopping list</h2>
<p>Next we'll take a look at how to build a shopping list where users can add new items to the list that they'd like to get from the store and delete items from the list.</p>
<h3 id="heading-final-result-3">Final result</h3>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codesandbox.io/embed/modest-feistel-zsttc9" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodeSandbox embed" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" loading="lazy"></iframe></div>
<h3 id="heading-how-to-build-it">How to build it</h3>
<p>This project will teach you how to add new items to an array in our local state using the array spread operator. Additionally, you'll learn how to delete any item we like using the <code>filter</code> function in JavaScript. </p>
<p>This project will also get you familiar with typing values into a form input and then retrieving those values when the form is submitted. You'll do this using the <code>onSubmit</code> event handler.</p>
<p>One fun way to enhance this project would be to enable our users to double click each item in our list to strike through it to put a line through it in addition to being able to delete it. </p>
<h3 id="heading-react-concepts-you-will-learn-3">React concepts you will learn</h3>
<ul>
<li>Updating lists with useState</li>
<li>JavaScript array spread operator and <code>filter</code> functions</li>
<li>Forms and inputs in React</li>
<li><code>onSubmit</code> event handler</li>
</ul>
<h2 id="heading-5-github-user-search">5. GitHub User Search</h2>
<p>In this project, we will use an input's value to search for users in GitHub using their username or email.</p>
<h3 id="heading-final-result-4">Final result</h3>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codesandbox.io/embed/mutable-sky-iesdhc" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodeSandbox embed" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" loading="lazy"></iframe></div>
<h3 id="heading-how-to-build-it-1">How to build it</h3>
<p>You will first store the value typed into the input in a state value called <code>query</code>. After that, you will perform an HTTP request to a GitHub API endpoint to then fetch the users' profile which once again uses the browser fetch API. The request URL will use the input value. </p>
<p>Once the results are fetched, we'll see how to display all the relevant info such as their name, avatar, and a link to go to their profile.</p>
<p>A good way to extend this project would be to attempt to allow search functionality as the user types instead of having to submit the form first. Make sure to use a debounce function to ensure that you do not too many requests to the GitHub API and get a 429 error response (too many requests).</p>
<h2 id="heading-6-video-player">6. Video Player</h2>
<p>React can also be used to work with the HTML video element and toggle between different videos.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codesandbox.io/embed/gifted-dirac-r6m0ns" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodeSandbox embed" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" loading="lazy"></iframe></div>
<h3 id="heading-how-to-build-it-2">How to build it</h3>
<p>In our project, we will allow users to toggle through several different videos using a radio input. We will not only see how to work with radio inputs in forms in React, but how to pass props down to our two components, <code>Menu</code> and <code>Video</code>. </p>
<p>In particular, we will learn how to pass down functions to update state in the parent components from the child component. This pattern is called lifting state up and is a very important pattern to know in React.</p>
<p>A fun way to improve this project would be to add a button to extend the functionality of the video player. For example, to add buttons to control whether the video is looped, whether the video autoplays, and more.</p>
<h3 id="heading-react-concepts-you-will-learn-4">React concepts you will learn</h3>
<ul>
<li>Radio inputs in React</li>
<li>Passing functions as props</li>
<li>Lifting state up in React</li>
</ul>
<h2 id="heading-7-bmi-calculator">7. BMI Calculator</h2>
<p>Finally we will build a simple BMI (body mass index) calculator which will use a person's weight and height in order to calculate their body mass index as a number.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codesandbox.io/embed/festive-water-c70hv3" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodeSandbox embed" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" loading="lazy"></iframe></div>
<h3 id="heading-how-to-build-it-3">How to build it</h3>
<p>We will use a couple of range inputs to enable our users to select their weight and height on a sliding scale. </p>
<p>Body mass index is calculated based off of the stored weight and height values. Our goal will be to calculated output their body mass index instantly, according to whatever values are stored in the <code>weight</code> and <code>height</code> state variables. </p>
<p>To do so, we will use the <code>useMemo</code> React hook to performantly calculate this value whenever either of these two values changed.</p>
<h3 id="heading-react-concepts-you-will-learn-5">React concepts you will learn</h3>
<ul>
<li>Range inputs in React</li>
<li>useMemo (to performantly perform calculations)</li>
</ul>
<h2 id="heading-become-a-professional-react-developer">Become a Professional React Developer</h2>
<p>React is hard. You shouldn't have to figure it out yourself.</p>
<p>I've put everything I know about React into a single course, to help you reach your goals in record time:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><strong>Introducing: The React Bootcamp</strong></a></p>
<p><strong>It’s the one course I wish I had when I started learning React.</strong></p>
<p>Click below to try the React Bootcamp for yourself:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a>
<em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ React Hooks You Can Use in Every Project – Explained with Examples ]]>
                </title>
                <description>
                    <![CDATA[ Hooks are one of the most powerful features of React.  They enable us to easily reuse functionality across our application's components. What's best about hooks is their reusability – you can reuse your hooks both across components and your projects.... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/react-hooks-every-project-should-use/</link>
                <guid isPermaLink="false">66d037c3ccf811d3117aeeed</guid>
                
                    <category>
                        <![CDATA[ hooks ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Fri, 06 Jan 2023 19:23:16 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/7-react-hooks.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Hooks are one of the most powerful features of React. </p>
<p>They enable us to easily reuse functionality across our application's components. What's best about hooks is their reusability – you can reuse your hooks both across components and your projects.</p>
<p>Here are seven of the most important React hooks that I reuse across every react project I create. Give them a try today and see if they're as useful for you when building your own React apps.</p>
<p>Before we begin, it's important to clarify that not every custom React hook needs to be written by you. In fact, all of the hooks that I will mention come from the library <code>@mantine/hooks</code>. </p>
<p>Mantine is great third-party library that includes these hooks and many more. They will add just about every significant feature to your React app that you can think of.</p>
<p>You can check out the documentation for <code>@mantine/hooks</code> at <a target="_blank" href="https://mantine.dev">mantine.dev</a>.</p>
<h2 id="heading-the-useintersection-hook">The <code>useIntersection</code> Hook</h2>
<p>When a user scrolls down the page in your application, you may want to know when an element is visible to them. </p>
<p>For example, you might want to start an animation only when a user sees a specific element. Or, you may want to show or hide an element after they've scrolled a certain amount down the page. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/use-intersection.gif" alt="Image" width="600" height="400" loading="lazy">
<em>useIntersection demo</em></p>
<p>To get information about whether an element is visible, we can use the <strong>Intersection Observer API.</strong> This is a JavaScript API that's built into the browser. </p>
<p>We can use the API on its own using plain JavaScript, but a great way to get information about whether a particular element is being intersected within its scroll container is to use the <code>useIntersection</code> hook. </p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { useRef } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { useIntersection } <span class="hljs-keyword">from</span> <span class="hljs-string">'@mantine/hooks'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Demo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> containerRef = useRef();
  <span class="hljs-keyword">const</span> { ref, entry } = useIntersection({
    <span class="hljs-attr">root</span>: containerRef.current,
    <span class="hljs-attr">threshold</span>: <span class="hljs-number">1</span>,
  });

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">main</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">{containerRef}</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">overflowY:</span> '<span class="hljs-attr">scroll</span>', <span class="hljs-attr">height:</span> <span class="hljs-attr">300</span> }}&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">{ref}</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>
          {entry?.isIntersecting ? 'Fully visible' : 'Obscured'}
        <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span></span>
  );
}
</code></pre>
<p>To use it, all we need to do is call the hook in our component and provide a root element. Root is the scroll container, and this can be provided as a ref with the <code>useRef</code> hook. <code>useIntersection</code> returns a ref which we pass to the target element, whose intersection in the scroll container we want to observe.</p>
<p>Once we have a reference to the element, we can keep track of whether the element is intersecting or not. In the example above, we can see when the element is obscured or when it's fully visible based off the value of <code>entry.isIntersecting</code>. </p>
<p>You can pass additional arguments that allow you to configure the <strong>threshold</strong> which is related to what percentage of the target is visible.</p>
<h2 id="heading-the-usescrolllock-hook">The <code>useScrollLock</code> Hook</h2>
<p>Another hook related to scrolling is the <code>useScrollLock</code> hook. This hook is very simple: it enables you to lock any scrolling on the body element. </p>
<p>I have found it to be helpful whenever you want to display an overlay or a modal over the current page and do not want to allow the user to scroll up and down on the page in the background. This lets you either focus attention on the modal or allow scrolling within its own scroll container.</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { useScrollLock } <span class="hljs-keyword">from</span> <span class="hljs-string">'@mantine/hooks'</span>;
<span class="hljs-keyword">import</span> { Button, Group } <span class="hljs-keyword">from</span> <span class="hljs-string">'@mantine/core'</span>;
<span class="hljs-keyword">import</span> { IconLock, IconLockOpen } <span class="hljs-keyword">from</span> <span class="hljs-string">'@tabler/icons'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Demo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [scrollLocked, setScrollLocked] = useScrollLock();

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Group</span> <span class="hljs-attr">position</span>=<span class="hljs-string">"center"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Button</span>
        <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> setScrollLocked((c) =&gt; !c)}
        variant="outline"
        leftIcon={scrollLocked ? <span class="hljs-tag">&lt;<span class="hljs-name">IconLock</span> <span class="hljs-attr">size</span>=<span class="hljs-string">{16}</span> /&gt;</span> : <span class="hljs-tag">&lt;<span class="hljs-name">IconLockOpen</span> <span class="hljs-attr">size</span>=<span class="hljs-string">{16}</span> /&gt;</span>}
      &gt;
        {scrollLocked ? 'Unlock scroll' : 'Lock scroll'}
      <span class="hljs-tag">&lt;/<span class="hljs-name">Button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">Group</span>&gt;</span></span>
  );
}
</code></pre>
<p><code>useScrollLock</code> locks the user's scroll at their current position on the page. The function returns an array, which can be destructured, as in the code above. </p>
<p>The second value is a function that allows us to lock the scroll. The first destructured value, on the other hand, is a boolean that tells us whether the scroll has been locked or not. </p>
<p>This value is useful for example, if you want to show certain content when the scroll is locked or to tell the user that it has been locked. You can see in the example below that we are indicating within our button when the scroll has been locked or unlocked.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/use-scroll-lock.gif" alt="Image" width="600" height="400" loading="lazy">
<em>useScrollLock demo</em></p>
<h2 id="heading-the-useclipboard-hook">The <code>useClipboard</code> Hook</h2>
<p>In many cases, you want to provide a button that allows the user to copy something to their clipboard, which is where copied text is stored. </p>
<p>A great example of this is if you have a code snippet on your website and you want to users to easily copy it. For this, we can use another web API – the <strong>Clipboard API</strong>. </p>
<p><code>@mantine/hooks</code> gives us a convenient <code>useClipboard</code> hook, which returns a couple of properties: <code>copied</code>, which is a boolean that tells us whether a value has been copied to the clipboard using the hook as well as a <code>copy</code> function, to which we can pass whatever string value we like to it to be copied. </p>
<p>In our example, we would like to copy a code snippet for our users to paste where they like, as seen in the video below: </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/use-clipboard.gif" alt="Image" width="600" height="400" loading="lazy">
<em>useClipboard demo</em></p>
<p>We call our <code>copy</code> function when they hit our designated copy button, pass to it the code snippet, and then show a little checkmark or something that indicates to them that the text has been copied. </p>
<p>What's neat is the <code>useClipboard</code> hook comes with a <strong>timeout value</strong>. After a given timeout period, which is in milliseconds, the copied state will be reset, showing the user that they can copy the text again.</p>
<h2 id="heading-the-usedebouncedvalue-hook">The <code>useDebouncedValue</code> Hook</h2>
<p>The next hook, <code>useDebouncedValue</code>, is essential if you have a search input in your app.</p>
<p>Whenever a user performs a search using an input, the search operation usually involves an HTTP request to an API. </p>
<p>A typical problem you will encounter, especially if you want your users to receive search results as they are typing, is that a query (request) will be performed on every keystroke. Even for a simple search query, there is no need to perform so many requests before a user has finished typing what they want. </p>
<p>This is a great use case for the <code>useDebounceValue</code> hook, which applies a debounce function on the text that's has been passed to it. </p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { useDebouncedValue } <span class="hljs-keyword">from</span> <span class="hljs-string">'@mantine/hooks'</span>;
<span class="hljs-keyword">import</span> { getResults } <span class="hljs-keyword">from</span> <span class="hljs-string">'api'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Demo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [value, setValue] = useState(<span class="hljs-string">''</span>);
  <span class="hljs-keyword">const</span> [results, setResults] = useState([])
  <span class="hljs-keyword">const</span> [debounced] = useDebouncedValue(value, <span class="hljs-number">200</span>); <span class="hljs-comment">// wait time of 200 ms</span>

  useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">if</span> (debounced) {
      handleGetResults() 
    }

    <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleGetResults</span>(<span class="hljs-params"></span>) </span>{
       <span class="hljs-keyword">const</span> results = <span class="hljs-keyword">await</span> getResults(debounced)   
       setResults(results)
    }
  }, [debounced])

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
        <span class="hljs-attr">label</span>=<span class="hljs-string">"Enter search query"</span>
        <span class="hljs-attr">value</span>=<span class="hljs-string">{value}</span>
        <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">flex:</span> <span class="hljs-attr">1</span> }}
        <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(event)</span> =&gt;</span> setValue(event.currentTarget.value)}
      /&gt;
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>{results.map(result =&gt; <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>{result}<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>}<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;/&gt;</span></span>
  );
}
</code></pre>
<p>You store the text from your input in a piece of state with <code>useState</code> and pass the state variable to <code>useDebouncedValue</code>. </p>
<p>As the second argument to that hook, you can provide a wait time, which is the period of time that the value is debounced. The debounce is what enables us to perform far fewer queries.</p>
<p>You can see the result in the video below where the user types something and only after 200 milliseconds, do we see the debounced value.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/use-debounced-value.gif" alt="Image" width="600" height="400" loading="lazy">
<em>useDebouncedValue demo</em></p>
<h2 id="heading-the-usemediaquery-hook">The <code>useMediaQuery</code> Hook</h2>
<p>Another very useful hook that I use all the time is the <code>useMediaQuery</code> hook. </p>
<p>Media Queries are used in plain CSS and the <code>useMediaQuery</code> hook allows us to subscribe to whatever media query we pass to the hook. </p>
<p>For example, within our component, let's say that we want to show some text or change the styles of a component based off of a certain screen width, such as 900 pixels. We provide a media query just like we would in CSS and <code>useMediaQuery</code> returns to us a <code>matches</code> value which is either true or false.</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { useMediaQuery } <span class="hljs-keyword">from</span> <span class="hljs-string">'@mantine/hooks'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Demo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> matches = useMediaQuery(<span class="hljs-string">'(min-width: 900px)'</span>);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">color:</span> <span class="hljs-attr">matches</span> ? '<span class="hljs-attr">teal</span>' <span class="hljs-attr">:</span> '<span class="hljs-attr">red</span>' }}&gt;</span>
      {matches ? 'I am teal' : 'I am red'}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<p>It tells us the result of that media query in JavaScript, which is particularly useful when we have styles that we want to change directly within our JSX using the <code>style</code> prop, for example. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/use-media-query.gif" alt="Image" width="600" height="400" loading="lazy">
<em>useMediaQuery</em></p>
<p>In short, this is an essential hook for those handful of cases in which CSS cannot be used to handle media queries. </p>
<h2 id="heading-the-useclickoutside-hook">The <code>useClickOutside</code> Hook</h2>
<p>This next hook – <code>useClickOutside</code> – might seem like a strange one, but you'll see how important it is when you actually need it. </p>
<p>When you develop a dropdown or something that pops up in front of a page's content and needs to be closed afterwards (such as a modal or drawer), this hook is indispensable. It's very easy to open one of these types of components by clicking a button. Closing these components is a little harder. </p>
<p>To follow good UX practices, we want anything that obstructs our user's view to be easily closable by clicking outside of the element. This is specifically what the <code>useClickOutside</code> hook lets us do. </p>
<p>When we call <code>useClickOutside</code>, it returns a ref that we must pass to the element outside of which we want to detect clicks. Usually that element is going to be controlled by a boolean piece of state such as the one we have in our example below (that is, the value <code>opened</code>). </p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { useClickOutside } <span class="hljs-keyword">from</span> <span class="hljs-string">'@mantine/hooks'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Demo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [opened, setOpened] = useState(<span class="hljs-literal">false</span>);
  <span class="hljs-keyword">const</span> ref = useClickOutside(<span class="hljs-function">() =&gt;</span> setOpened(<span class="hljs-literal">false</span>));

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> setOpened(true)}&gt;Open dropdown<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      {opened &amp;&amp; (
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">{ref}</span> <span class="hljs-attr">shadow</span>=<span class="hljs-string">"sm"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Click outside to close<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      )}
    <span class="hljs-tag">&lt;/&gt;</span></span>
  );
}
</code></pre>
<p><code>useClickOutside</code> accepts a callback function which controls what happens when you actually click outside that element. </p>
<p>In most cases, we want to do something quite simple, which is to just close it. To do so, you'll likely need to have a state setter (like <code>setOpened</code>) and pass it a value of false to then hide your overlayed content.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/use-click-outside.gif" alt="Image" width="600" height="400" loading="lazy">
<em>useClickOutside demo</em></p>
<h2 id="heading-the-useform-hook">The <code>useForm</code> Hook</h2>
<p>My favorite and most helpful hook in this list is the <code>useForm</code> hook. </p>
<p>This hook comes specifically from Mantine and involves installing a specific package from the library: <code>@mantine/form</code>. It should give you everything that you need to create forms in React, including the ability to validate inputs, display error messages, and ensure the input values are correct before the form is submitted.</p>
<p><code>useForm</code> accepts some initial values which correspond to whatever inputs you have within your form.</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { TextInput, Button } <span class="hljs-keyword">from</span> <span class="hljs-string">'@mantine/core'</span>;
<span class="hljs-keyword">import</span> { useForm } <span class="hljs-keyword">from</span> <span class="hljs-string">'@mantine/form'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Demo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> form = useForm({
    <span class="hljs-attr">initialValues</span>: {
      <span class="hljs-attr">email</span>: <span class="hljs-string">''</span>
    },

    <span class="hljs-attr">validate</span>: {
      <span class="hljs-attr">email</span>: <span class="hljs-function">(<span class="hljs-params">value</span>) =&gt;</span> (<span class="hljs-regexp">/^\S+@\S+$/</span>.test(value) ? <span class="hljs-literal">null</span> : <span class="hljs-string">'Invalid email'</span>),
    },
  });

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">onSubmit</span>=<span class="hljs-string">{form.onSubmit((values)</span> =&gt;</span> console.log(values))}&gt;
        <span class="hljs-tag">&lt;<span class="hljs-name">TextInput</span>
          <span class="hljs-attr">withAsterisk</span>
          <span class="hljs-attr">label</span>=<span class="hljs-string">"Email"</span>
          <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"your@email.com"</span>
          {<span class="hljs-attr">...form.getInputProps</span>('<span class="hljs-attr">email</span>')}
        /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">Button</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<p>The great benefit of <code>useForm</code> is its helpers, such as the <code>validate</code> function, which receives the value that's been typed in to each input then allows you to create validation rules. </p>
<p>For example, if you have an email input, you might have a regular expression to determine whether it is in fact a valid email (as you can see in the code above). If not, then you can show an error message and prevent the form from being submitted. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/use-form.gif" alt="Image" width="600" height="400" loading="lazy">
<em>useForm demo</em></p>
<p>How do you get the values that have been typed into the form? </p>
<p>Mantine provides a very convenient helper called <code>getInputProps</code>, where you simply provide the name of the input you're working with (like email) and it automatically sets up an onChange to keep track of the values that you've typed into your form. </p>
<p>Additionally, to handle form submission and prevent submission if its values do not pass validation rules, it has a special <code>onSubmit</code> function which you wrap around your regular onSubmit function. On top of applying the validation rules, it will take care of calling <code>preventDefault()</code> on the form event so that you don't have to do it manually. </p>
<p>I am just scratching the surface with this hook, but I would highly recommend you use it for your next project. Forms are traditionally a pain to get working properly, especially forms that require validation and visible error messages. <code>useForm</code> makes it incredibly easy!</p>
<h2 id="heading-become-a-professional-react-developer">Become a Professional React Developer</h2>
<p>React is hard. You shouldn't have to figure it out yourself.</p>
<p>I've put everything I know about React into a single course, to help you reach your goals in record time:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><strong>Introducing: The React Bootcamp</strong></a></p>
<p><strong>It’s the one course I wish I had when I started learning React.</strong></p>
<p>Click below to try the React Bootcamp for yourself:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a>
<em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ 8 React Projects to Build in 2023 ]]>
                </title>
                <description>
                    <![CDATA[ If you want to be good at React, building projects is one of the best ways to do it.  I have put together eight different projects that will not only show you what's possible to make with React, but give you some inspiration on what apps to make.  ]]>
                </description>
                <link>https://www.freecodecamp.org/news/react-projects-to-improve-your-skills/</link>
                <guid isPermaLink="false">66d037d764be048ac359a32d</guid>
                
                    <category>
                        <![CDATA[ projects ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Thu, 05 Jan 2023 00:22:40 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/12/8-react-projects.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you want to be good at React, building projects is one of the best ways to do it. </p>
<p>I have put together eight different projects that will not only show you what's possible to make with React, but give you some inspiration on what apps to make. </p>
<p>Additionally, I will give you all the tools that you need to effectively build out each project in the list. </p>
<p>Let's get started!</p>
<h2 id="heading-todo-app">Todo App</h2>
<p>If you want to get started building projects, there's no better starting place than a simple todo app.</p>
<p>A todo application will feature basic CRUD functionality, meaning that you can create, read, update and delete todos. Todos can be replaced with whatever type of content that you want. In fact, many applications we use on a daily basis could arguably be considered glorified todo apps. </p>
<p>The benefit of building a todo app is that the entire app can be made in a short period of time. If you can build a todo app without any tutorial to guide you, it is a good test to see your proficiency with React. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/Screen-Shot-2023-01-03-at-12.37.07-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>TodoMVC todo app</em></p>
<p>Todo apps are a great project to begin with because you do not need any third-party libraries to build them. You can make your todo app as complex as you like, which will help you become confident with concepts that you want to learn. Want to add authentication or a database to your app? Feel free to do so! You can truly make it as simple or complex as you like.</p>
<h3 id="heading-stack-to-use">Stack To Use</h3>
<ul>
<li>Barebones React app</li>
<li>Core React features (State, Context, and so on.)</li>
<li>That's it!</li>
</ul>
<h2 id="heading-personal-blog">Personal Blog</h2>
<p>A step up from the basic todo app is a blog website. </p>
<p>If you would like to write in <strong>Markdown</strong>, which is a popular style of writing and formatting text, your blog will likely consist of a number of Markdown (.md) files. </p>
<p>If you want the content to be included locally within the project to make it a bit more difficult, you could try fetching it from an external source like a CMS (content management system) such as Sanity or Contentful. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/Screen-Shot-2023-01-03-at-1.11.07-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Next Blog Starter Kit (https://next-blog-starter.vercel.app/)</em></p>
<p>In either case, this blog is going to consist of static pages so you can use any static site generator that you like. </p>
<p>A good framework choice for this blog could be <strong>Next.js</strong> or <strong>Gatsby</strong>. Both are ideal to make text-driven websites like blogs because they are server-rendered frameworks and give you better SEO. This is compared to a traditional client-rendered React app (one made with Create React App, for example). </p>
<p>Our stack will consist of one of these React frameworks plus a transformer to convert our markdown content into HTML when our site is built. A good choice to transform our markdown content is the <code>remark</code> npm package. </p>
<p>If you want to make an even more impressive blog, with dynamic content, then you can consider using <strong>MDX</strong>. MDX is very similar to plain markdown, but it also allows you to include your own custom React components within the markdown. </p>
<p>To use MDX, you would use a package like <code>next-mdx-remote</code> if you're using Next.js. The plain <code>mdx-js/mdx</code> package also works great.</p>
<h3 id="heading-stack-to-use-1">Stack To Use</h3>
<ul>
<li>Next.js/Gatsby</li>
<li>Markdown or MDX (<code>remark</code> or <code>mdx-js/mdx</code>)</li>
<li>CMS (Contentful or Sanity)</li>
</ul>
<p>Just a quick note: for each of these projects, I won't be talking about styling. I personally prefer using plain CSS in the form of TailwindCSS. You can head to Tailwind's website to see how to easily set that up for whatever React framework you're using.</p>
<h2 id="heading-e-commerce-app">E-commerce App</h2>
<p>The next step up from our blog project is an e-commerce app. </p>
<p>It has a lot of similar features to our blog, including the fact that most of the content is going to be largely static and unchanging. </p>
<p>Once again, the data can be sourced locally or fetched from a CMS at build time. What's different about an e-commerce app is that it allows us to venture into working with a server of some sort. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-15.png" alt="Image" width="600" height="400" loading="lazy">
<em>Next.js E-commerce App</em></p>
<p>If you want your customers to purchase an item through Stripe, for example, you might want to set up a <strong>webhook</strong> that will receive an event from Stripe when your customer has purchased a particular item. This is essential for managing things like your product inventory. </p>
<p>To very easily write server-side code, you could use an API route so that you don't have to set up a complete Node.js project. This function would process different events that take place upon checkout or after checkout. </p>
<p>Additionally, if you don't want to have to touch any server-side code, you can avoid the <code>stripe</code> npm package entirely and just use <strong>Stripe checkout</strong> or a <strong>Stripe payment link</strong>. </p>
<p>Going forward, every project that we're going to touch on will involve a server of some sort. Most every application you use has a backend and a frontend. React will always be the frontend of our application but be aware that for any of these projects, you can very easily set up a server for your application to handle things like talking with a database when you have a framework like Next.js. </p>
<p>Next.js includes a special type of page called an <strong>API route</strong>, which allows you to do server-side things such as authentication, webhooks, reading and writing to a database, and much more. Additionally, we'll touch on some solutions like Firebase that don't require you to make a backend at all!</p>
<h3 id="heading-stack-to-use-2">Stack To Use</h3>
<ul>
<li>Next.js</li>
<li>Stripe (using API Routes for webhooks)</li>
<li>CMS (Contentful or Sanity to store products)</li>
</ul>
<h2 id="heading-newscommunity-app-reddit-clone">News/Community App (Reddit Clone)</h2>
<p>A Reddit clone that is centered around sharing links or very simple posts is a good step up from our todo app. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/ezgif-4-3e6d6becfc.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Reddit clone, built with React</em></p>
<p>We are still creating, updating, and deleting data, but this time it's going to be saved in a database. We might allow users to add different types of content, like a video or a link or a short post. We can use Firebase for our project to get started, which will give us the <strong>Firestore database</strong>. </p>
<p>Our Firestore database will consist of a simple collection that will save all of the individual posts that a user has made. We can further develop it by allowing other users to add comments and likes to the posts. </p>
<p>An even more developed app would include authentication. Fortunately, <strong>Firebase Auth</strong> makes it very easy. We can also add likes to individual comments and replies to comments for our comment threads. </p>
<p>We could use any React framework for this. A good choice would be one using a <strong>Vite</strong> template. For our individual posts, we would need dynamic routes to fetch individual posts based off of their id. A good choice for that would be React Router.</p>
<h3 id="heading-stack-to-use-3">Stack To Use</h3>
<ul>
<li>React (bootstrapped with Vite)</li>
<li>React Router (install <code>react-router-dom</code>)</li>
<li>Firestore database (from Firebase)</li>
<li>Firebase Auth</li>
</ul>
<h2 id="heading-chat-app-discord-clone">Chat App (Discord Clone)</h2>
<p>To add to our Reddit app, we could make it into something like Discord by displaying messages in realtime. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/ezgif-4-bd75470d3f.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Discord clone, built with React</em></p>
<p>If we change the posts into threads, we now have a chat app where it's an ongoing conversation. </p>
<p>Like the Reddit clone, users can still add any type of media that they like. A good touch would be adding link previews so when a user shares a link, such as a YouTube video, other users can get a little card that displays what is actually linked to with an image before the user clicks on it. There's a library called <code>react-tiny-link</code> that allows you to do that.</p>
<p>We can still use Firebase for this project. This is a good use case for the Firebase realtime database so that we don't need to refresh or reload the page to see new messages. </p>
<p>Additionally, we can add different roles to our users in Discord. In the real Discord app, there are moderators with greater controls over the other users. One example feature would be to add a ban feature to remove a user from a given channel or community.</p>
<h3 id="heading-stack-to-use-4">Stack To Use</h3>
<ul>
<li>React (bootstrapped with Vite)</li>
<li>React Router (install <code>react-router-dom</code>)</li>
<li><code>react-tiny-link</code></li>
<li>Firebase realtime database</li>
<li>Firebase Auth</li>
</ul>
<h2 id="heading-messenger-app-whatsapp-clone">Messenger App (WhatsApp Clone)</h2>
<p>An offshoot of this type of realtime app would be a messenger-style app like that of WhatsApp.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/ezgif-4-4e59d05ac0.gif" alt="Image" width="600" height="400" loading="lazy">
<em>WhatsApp clone, made with React</em></p>
<p>This app would be a little bit more limited in that conversations are usually done with one person, although they don't have to be. Instead of talking in channels you will have different options to talk with one or another person at a time. </p>
<p>A good touch would be to add notifications when someone messages you. This is another app example that would require realtime data functionality from your database. Firebase is always a good option for that. </p>
<p>If Firebase gets boring, you could try Supabase which is a very competitive alternative also with realtime database features, but which is backed by Postgres instead of Firestore.</p>
<h3 id="heading-stack-to-use-5">Stack To Use</h3>
<ul>
<li>React (bootstrapped with Vite)</li>
<li>React Router (install <code>react-router-dom</code>)</li>
<li>Supabase</li>
</ul>
<h2 id="heading-social-media-app-twitter-clone">Social Media App (Twitter Clone)</h2>
<p>What if instead of having an app where one person talks directly with another person in a very confined space, you want the opposite, where anyone can interact with anyone! </p>
<p>A great example of this type of app would be Twitter.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/twitter-gif.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Twitter clone, made with React</em></p>
<p>Twitter is an app that requires a feed as well as a trending page in a user's feed. The user will be able to see all of the posts from the people that they follow. But on the trending page, they will see all of the most popular posts across the entire website. </p>
<p>To be able to figure out which posts are the most popular, you will add the ability to like (heart) a given post as well as re-share it, which allows a post to be added to or associated with another user. Finally, you will want to allow users to directly reply to other posts (like Twitter's "quote tweet" feature). </p>
<p>And another fundamental feature that could be added to every app that we've covered up until this point is search. In our Twitter clone, users would likely want to be able to search for different users to follow as well as posts based on their content. </p>
<p>One downside to Firebase is that it does not have the best tools for search and it's not easy to perform queries that are based on a certain keyword. This is one instance in which <strong>Supabase</strong> would be a superior alternative.</p>
<h3 id="heading-stack-to-use-6">Stack To Use</h3>
<ul>
<li>React (bootstrapped with Vite)</li>
<li>React Router (install <code>react-router-dom</code>)</li>
<li>Supabase or Firebase</li>
</ul>
<h2 id="heading-video-sharing-app-youtubetiktok-clone">Video Sharing App (YouTube/TikTok Clone)</h2>
<p>The last fun project in this list is a video sharing app such as YouTube or TikTok. </p>
<p>The two apps have very similar features, with YouTube primarily focusing on long form video content and Tiktok mainly consisting of super-short videos under a minute. </p>
<p>Both platforms utilize an infinite scroll feature, whether you're scrolling through suggested videos or recommended videos. TikTok itself is arguably just one big infinite-scrolling feed.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/ezgif-4-b958b9f166.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Tiktok clone, made with React</em></p>
<p>What would be hardest to implement about both these platforms is the algorithm. You could go very far on building an app that just relies on users following other users and having a homepage with the most popular videos. Your users would first be suggested videos from the people that they follow and then the popular videos on the site. </p>
<p>The most essential feature for both TikTok and YouTube is streaming video. To allow users to upload their own content you need a service that includes an upload API. Some good choices in this area are <strong>Cloudflare Stream</strong>, Video.js, or Mux. </p>
<p>All of these tools provide you with a video player as well as an API, which would handle uploading videos that could then be posted to the site. </p>
<p>I would personally build this app using my own server and database. I would probably choose <strong>Prisma</strong> as the ORM (object-relational mapped) to interact with the database which would be a <strong>MySQL</strong> database managed by Planetscale.</p>
<h3 id="heading-stack-to-use-7">Stack To Use</h3>
<ul>
<li>Next.js (with API Routes for interacting with database)</li>
<li>The <code>next-auth</code> package (to add Google Auth, among other auth providers)</li>
<li>Cloudflare stream or Video.js (as our video player and to host our videos)</li>
<li>Prisma (as our ORM)</li>
<li>MySQL (managed by Planetscale)</li>
</ul>
<h2 id="heading-become-a-professional-react-developer">Become a Professional React Developer</h2>
<p>React is hard. You shouldn't have to figure it out yourself.</p>
<p>I've put everything I know about React into a single course, to help you reach your goals in record time:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><strong>Introducing: The React Bootcamp</strong></a></p>
<p><strong>It’s the one course I wish I had when I started learning React.</strong></p>
<p>Click below to try the React Bootcamp for yourself:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a>
<em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Learn React in 2023 ]]>
                </title>
                <description>
                    <![CDATA[ As the most popular JavaScript library for building frontend applications, there has never been a better year to learn React than 2023.  In this guide, I'm going to show you the most valuable resources and tips that I believe will help you learn Reac... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-learn-react-in-2023/</link>
                <guid isPermaLink="false">66d03781c1024fe75b758f49</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Mon, 02 Jan 2023 22:59:24 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/12/learn-react-2023.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>As the most popular JavaScript library for building frontend applications, there has never been a better year to learn React than 2023. </p>
<p>In this guide, I'm going to show you the most valuable resources and tips that I believe will help you learn React faster. You'll also save a lot of precious time and energy in the process. </p>
<h2 id="heading-need-to-learn-javascript-you-can-learn-it-while-learning-react">Need to Learn JavaScript? You Can Learn it While Learning React</h2>
<p>The question I'm most frequently asked by beginners looking to learn React is: "do I need to learn JavaScript?"</p>
<p>React is a JavaScript library and is often advertised as being "just JavaScript." This suggests that to really learn React you must know JavaScript first. The way I would characterize JavaScript's relationship to React is–<em>the better you know JavaScript, the better a React developer you will become</em>.</p>
<p>With that being said, you do <strong>not</strong> need to learn all of JavaScript first. Many JavaScript concepts can be learned at the same time you are learning React. </p>
<p>Here is a shortlist of some of the concepts in JavaScript that you will need to understand to be able to use React effectively. These include:</p>
<ul>
<li>Variables </li>
<li>Arrays (and the .map() function) </li>
<li>Objects</li>
<li>JavaScript events</li>
<li>Functions and arrow functions </li>
<li>Scopes and closures </li>
<li>Promises and async-await syntax. </li>
<li>Basic error handling</li>
</ul>
<p>These are all the JavaScript concepts that, in my experience, you truly need to know to work with React at any level. </p>
<p>You will encounter and learn more React concepts as you start building your own projects and looking at the code of others. </p>
<p>If you want a helpful guide to start learning these concepts and more today, I've written an <a target="_blank" href="https://www.freecodecamp.org/news/javascript-skills-you-need-for-react-practical-examples/">extensive cheatsheet on freeCodeCamp</a> that covers all the JavaScript that you need to be confident with React.</p>
<h2 id="heading-looking-for-a-tutorial-use-the-new-react-docs">Looking for a Tutorial? Use the New React Docs</h2>
<p>When you first begin your React learning path, your first question will likely be: "where do I learn all the React-related information I need?" You might be asking whether you should watch courses on YouTube or purchase a course on Udemy. </p>
<p>While there are great and extensive React courses across many different sites, the first and primary site you should rely on is the official React documentation site: <a target="_blank" href="https://reactjs.org/">reactjs.org</a>. </p>
<p>What's very special about learning React in 2023 versus learning it in previous years is that in the past year, the React documentation that has been completely updated and improved. It is entirely up-to-date with the current React version, has tons of practical examples, and even interactive code sandboxes so that you can start learning react in the browser without having to create projects on your own machine. </p>
<blockquote>
<p>If you ever want to spin up a new React project, you can do it very quickly in the browser using the link <a target="_blank" href="https://react.new">react.new</a>. This will create a CodeSandbox with a complete React application with which you can mess around. It's much faster and easier to do that creating a project on your own computer. </p>
</blockquote>
<p>You can find the new React documentation at <a target="_blank" href="https://beta.reactjs.org">beta.reactjs.org</a>. In due time, you will be able to find it simply on reactjs.org. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/Screen-Shot-2023-01-02-at-5.27.01-AM.png" alt="Image" width="600" height="400" loading="lazy">
<em>beta.reactjs.org</em></p>
<p>Another big reason to use the new React documentation is that it is very beginner-friendly and will, in my opinion, allow you to learn concepts much faster than you would otherwise. If you have been intimidated to reading technical documentation in the past, I think you will be pleasantly surprised.</p>
<h2 id="heading-you-dont-need-to-learn-class-components">You Don't Need to Learn Class Components</h2>
<p>If you are wondering whether you need to learn class components in 2023, you do not. </p>
<p>As you begin to learn React, you will hear about this thing called a <strong>class component</strong> which is based around a normal JavaScript class. This is no longer necessary to learn as a React developer, but it can still benefit you to learn it.</p>
<p>After the introduction of a feature called <strong>React hooks</strong> in 2018, React developers have moved over to using function components, which are made with JavaScript functions. </p>
<p>Class components are still a part of React and they are still used in production code in a number of instances (such as error boundaries). But just be aware that you do not need to learn them in order to be skilled at React. </p>
<p>In fact, I've rarely encountered them unless I'm looking at an older code base. Most of them have been migrated over to function components and React hooks already.</p>
<h2 id="heading-do-yourself-a-favor-and-learn-react-query">Do Yourself a Favor and Learn React Query</h2>
<p>Any serious application requires data. Often the data that you need will exist outside your application, so you will need a strategy to fetch it and use in your project. </p>
<p>When you get to the point of fetching data I would highly recommend that you learn a library called <strong>React Query</strong>. </p>
<p>You can install React Query through the npm package @tanstack/react-query.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/Screen-Shot-2023-01-02-at-5.28.02-AM.png" alt="Image" width="600" height="400" loading="lazy">
<em>React Query, also called Tanstack Query</em></p>
<p>React Query has become the go-to library for fetching and managing external data in React applications. </p>
<p>What's the benefit of using React Query? On top of being a library so many React developers and companies are now familiar with and rely upon, it will benefit you greatly to learn React Query because it is arguably the most powerful way for you to fetch and manage external data in your React applications. </p>
<p>The greatest benefit of using React Query comes from that fact that is gives you a cache (a store) that lets you hold on to the result of each query, so you can "save" the data that you've fetched. Plus it has many tools to update that cache exactly the way you want. </p>
<p>It also features relevant information about the status of every query you make such as whether it is loading or it resulted in an error.</p>
<p>I would learn React Query after you are comfortable manually fetching data using tools like the Fetch API or Axios with the useEffect hook. Once you are, you will see the benefit of using React Query across all of your React projects.</p>
<h2 id="heading-you-dont-need-to-learn-redux">You Don't Need to Learn Redux</h2>
<p>If you've tried to learn React in years past, you might have gotten the impression that to learn React, you ultimately had to learn another library called Redux. </p>
<p><strong>Redux</strong> is a library that helps us manage state in our React applications. You can think of state as any data that might change in a React app. Redux enables us to manage one piece of state (like, is our user logged in) across every part of our React application. </p>
<p>Redux is no longer required to learn like it was in years past. The first reason for this is the release of the <strong>React Context</strong> API. In many cases, React developers used Redux to just pass data around their application's components. This is a job that React Context can do for us.</p>
<p>Additionally, if you need to change or update state in many different parts of your app (which is a different requirement that simply reading your state), there are many competitors to Redux. Unlike Redux, these libraries do not require that you learn new concepts, such as reducers, actions, and so on. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image.png" alt="Image" width="600" height="400" loading="lazy">
<em>Zustand - "Bearbone" state management</em></p>
<p>Some of these newer, "lighter" state management libraries include:</p>
<ul>
<li><strong>Zustand</strong></li>
<li>Jotai</li>
<li>Recoil</li>
</ul>
<p>Once you get past the basics of React and begin building slightly larger applications beyond the standard todo app, you will understand the need for having a state management library. Redux is still a great library, but first look to a library with a simpler API such as Zustand.</p>
<h2 id="heading-dont-necessarily-reach-for-create-react-app">Don't Necessarily Reach for Create React App</h2>
<p>Once you are at the point of creating a React project on your own that lives on your computer, know that there are many ways of doing this. </p>
<p>Web development in general is moving more and more online – not every React project has to be made on your computer. In many cases you can spin up a brand new project in the browser using tools like <strong>CodeSandbox</strong> or <strong>StackBlitz</strong> entirely free of charge. </p>
<p>There will be a point, however, where you will need or want to create a React project on your local machine. It is easy to reach for a tool like <strong>Create React App</strong>, which allows you to make a React project by running a single command.</p>
<p>Create React App is still a great tool to make React projects. Just like with Redux, new alternatives have emerged give you all the conveniences of Create React, but in a smaller, often faster package. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/Screen-Shot-2023-01-02-at-5.30.02-AM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Vite, an alternative to Create React App</em></p>
<p>The primary example of this is <strong>Vite</strong>. Vite is a build tool that allows you to spin up a new React project as well as many other kinds of JavaScript projects. </p>
<p>The benefit of using Vite the over Create React App is that it gives you a much faster development server. </p>
<p>To develop and make changes to your app, it must run on a development server. Create React Appl, by comparison, can take a relatively long time to start up and respond to changes in code that you make (this is called <strong>hot reloading</strong>). Vite provides a much faster experience in addition to requiring far fewer dependencies. </p>
<p>Another great alternative to Create React App is <strong>Next.js</strong>. Next is technically a React framework, which comes with many conveniences to make development a lot easier. It comes with its own router and data fetching tools, to name a couple. </p>
<p>The benefit of using a framework like Next.js is that you simply have to make fewer decisions when it comes to building your project. You need to pick far fewer dependencies upon which your project relies. Most everything that you need to build your React app comes built in to Next.js </p>
<p>With that being said, Next operates quite differently than normal React projects due to the fact that it's server-rendered by default. This can comes with its own problems and potential pitfalls to avoid. But if you're interested in building serious, production-ready React projects, Next is arguably the best choice. </p>
<h2 id="heading-become-a-professional-react-developer">Become a Professional React Developer</h2>
<p>React is hard. You shouldn't have to figure it out yourself.</p>
<p>I've put everything I know about React into a single course, to help you reach your goals in record time:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><strong>Introducing: The React Bootcamp</strong></a></p>
<p><strong>It’s the one course I wish I had when I started learning React.</strong></p>
<p>Click below to try the React Bootcamp for yourself:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a>
<em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Have Fun Building React Apps ]]>
                </title>
                <description>
                    <![CDATA[ Building React apps can either be a very fun experience or a very difficult and tedious one, based off of the tools you choose.   React is a JavaScript library that, unlike frameworks like Angular, leave us to making a lot of decisions on our own. Yo... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/have-fun-building-react-apps/</link>
                <guid isPermaLink="false">66d0376cc1024fe75b758f3e</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Mon, 19 Dec 2022 21:41:26 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/12/mugshotbot.com_customize_color-teal-discounted_price--image-fa229fca-mode-light-pattern-charlie_brown-price--theme-e_commerce-url-https___gifcoins.io.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Building React apps can either be a very fun experience or a very difficult and tedious one, based off of the tools you choose.  </p>
<p>React is a JavaScript library that, unlike frameworks like Angular, leave us to making a lot of decisions on our own. You have to choose which tools and libraries you would like to power your React projects. </p>
<p>I want to share my top five choices with you for building React apps. I believe these will enable you to have the most fun experience by making your app development easier, faster and, most importantly, simpler. </p>
<h2 id="heading-want-to-build-a-web-app-use-nextjs">Want to Build a Web App? Use Next.js</h2>
<p>Probably the most important choice you can make in building a React app is whether to choose a React framework or not.</p>
<p>There are many different React frameworks on the market, such as Gatsby and Redwood.js, to name a couple. </p>
<p>Next.js, however, continues to be an equally great option for both full-stack applications and static sites.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/Screen-Shot-2022-12-19-at-2.45.12-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>nextjs.org, the official documentation site for Next.js</em></p>
<p>Need to build a full-stack app with a Node server? Next.js gives you API routes out of the box, which just lets you drop an API endpoint in your pages directory that will be executed as a serverless function.</p>
<p>Want to build a static site that pulls data from a CMS? No problem. Next gives you static-site generation to request that data at build time and exports your site as plain HTML, CSS, and JavaScript.</p>
<p>Next.js does the heavy lifting for all kind of essential tasks that you will encounter as you build your app. </p>
<p>For example, Next.js gives you tools to...</p>
<ul>
<li>Effortlessly integrate with TypeScript</li>
<li>Preload custom fonts (@next/font)</li>
<li>Handle simple and dynamic routing</li>
<li>Server-side render your content</li>
<li>Use environment variables with zero configuration</li>
<li>Add custom redirects, rewrites, and headers</li>
</ul>
<p>All of this and much more is available through the <code>next</code> npm library. The reason it makes good sense to build with Next is that there are many things that Next.js provides that you haven't even thought of yet. </p>
<p>Despite being a pretty comprehensive framework, Next.js isn't going to be the only dependency you need. For example, Next.js doesn't provide authentication. However, there are some great tools such as <code>next-auth</code> and Blitz.js that will give you easy authentication with Next. </p>
<p>If Next.js can't do something for you directly, you can still find lots of solutions at the Next.js website (plus great documentation) for almost everything your React app will need. </p>
<h2 id="heading-need-to-fetch-data-use-react-query">Need to Fetch Data? Use React Query</h2>
<p>If you're doing any type of data fetching within your application, you should be using React Query. </p>
<p>Note that the library is called @tanstack/react-query for React Query version 4.</p>
<p>React Query is a very powerful library that allows us to fetch data or handle any type of asynchronous operation using a set of custom hooks, namely <code>useQuery</code> and <code>useMutation</code>. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/Screen-Shot-2022-12-19-at-2.43.30-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>React Query, also known as TanStack Query</em></p>
<p>The whole purpose of React query is to make data fetching (called <em>querying</em>) and updating data (<em>mutating</em>) an enjoyable and much easier experience than it was in the past. </p>
<p>Previously, you might have fetched data or done some sort of async action within the useEffect hook. The problem with doing so in most cases is that this operation will always be performed on component mount. That means if your component is loaded within a particular page, that operation will be performed every time the page loads.</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { useQuery } <span class="hljs-keyword">from</span> <span class="hljs-string">'@tanstack/react-query'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> info = useQuery({ <span class="hljs-attr">queryKey</span>: [<span class="hljs-string">'todos'</span>], <span class="hljs-attr">queryFn</span>: fetchTodoList })
}
</code></pre>
<p>The downside is that you are most likely performing that operation far more than you need to. If you are fetching data and the data does not change, what's the point of fetching it again? </p>
<p>That's where React Query comes in. By giving us far greater control over our data fetching, we are able to specify when we want to fetch and refetch a query.</p>
<p>Additionally, if we're fetching data and it has changed, React Query will default to giving us the cached data first, which is then replaced with the new data. The benefit of this is that we don't have to see a loading spinner every time the data we are fetching changes. </p>
<p>In short, React Query gives us total control over the external data within our application and gives us a convenient cache with sensible defaults so that we have a far better experience for our users with far fewer loading spinners. </p>
<p>There's a bit of a learning curve with React query, but once you get used to it, you'll wonder how you ever built a React application without it. </p>
<h2 id="heading-need-to-manage-state-use-zustand">Need to Manage State? Use Zustand</h2>
<p>Managing state in the past usually required installing the library Redux once your project got to a certain size. </p>
<p>Redux is still a great library with the somewhat recent addition of Redux Toolkit. In most cases, however, Redux may be more sophisticated than what you need. </p>
<p>Zustand is a library that makes managing global state and React applications dead simple. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/image-107.png" alt="Image" width="600" height="400" loading="lazy">
<em>Zustand State Management library</em></p>
<p>All you have to do to manage a certain value is to import the zustand package, create a store (which is just a function call that accepts an object), place the property that you want to manage on that object, and use this store as a hook throughout your application. That's it! </p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> create <span class="hljs-keyword">from</span> <span class="hljs-string">'zustand'</span>

<span class="hljs-keyword">const</span> useCounterStore = create({ <span class="hljs-attr">count</span>: <span class="hljs-number">0</span> })
</code></pre>
<p>Updating that state is as simple as using the internal <code>set</code> function. With it, we can make methods on this object which we can update any state value the way we like. It's really that simple. </p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> create <span class="hljs-keyword">from</span> <span class="hljs-string">'zustand'</span>

<span class="hljs-keyword">const</span> useCounterStore = create(<span class="hljs-function">(<span class="hljs-params">set, get</span>) =&gt;</span> ({ 
  <span class="hljs-attr">count</span>: <span class="hljs-number">0</span>,
  <span class="hljs-attr">increaseCount</span>: get().count + <span class="hljs-number">1</span> <span class="hljs-comment">// increases count value by 1</span>
}))
</code></pre>
<p>The great benefit of using Zustand is that it doesn't require any provider – you don't need to wrap any thing around your React component tree. Additionally, this state can be consumed within any React component, even outside of your React components entirely. </p>
<p>Zustand also gives you control over how your components update in response to a state change. If you don't mind your components re-rendering on every state change, you can grab the entire state:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> state = useCounterStore()
</code></pre>
<p>However, if you want to only update a component when one particular value changes, you can select the slice of state you want:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> count = useCounterStore(<span class="hljs-function">(<span class="hljs-params">state</span>) =&gt;</span> state.count)
</code></pre>
<p>Zustand takes what is a fundamentally intimidating thing – managing shared state across many different components – and turns it into a very simple and even enjoyable experience due to its easy syntax and many conveniences. </p>
<h2 id="heading-want-animations-use-framer-motion">Want Animations? Use Framer Motion</h2>
<p>Perhaps the most fun part of any application is adding visual effects like transitions and animations. Framer Motion is makes the process of developing any kind of transition and animation easy.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/Screen-Shot-2022-12-19-at-3.19.40-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Framer Motion (framer.com/docs)</em></p>
<p>Framer Motion is a package that allows you to do really impressive animations of almost any kind. Whether it is simple transitions, gestures, or complex layout animations framer has you covered. </p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codesandbox.io/embed/framer-motion-animate-on-state-update-ns67ib?fontsize=14&amp;hidenavigation=1&amp;theme=dark" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodeSandbox embed" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" loading="lazy"></iframe></div>
<p>The benefit of using Framer Motion is that it provides a very simple declarative API for how you want your animation to take place. </p>
<p>To use Framer, you just swap whatever JSX element you want to animate, such as a <code>div</code> with <code>motion.div</code>. </p>
<p>Once we use this special motion component, we can pass it a number of props which control animation. The only prop we really need, though, to animate our components is the <code>animate</code> prop.</p>
<pre><code class="lang-jsx">&lt;motion.div animate={{ <span class="hljs-attr">x</span>: <span class="hljs-number">100</span> }} /&gt;
</code></pre>
<p>This props additionally allows us to set up what its initial position will be, how it will animate, and if it exits the DOM, what the exit animation will look like. </p>
<p>Framer gives us just the same controls as plain CSS animations, such the ability to delay the animation or choose its easing curve. Additionally, it gives a ton more options through custom hooks and components, as well as special values that we can set. </p>
<p>With Framer Motion, we can:</p>
<ul>
<li>Animate when components are reordered with the <code>Reorder</code> component</li>
<li>Create scroll-linked animations with <code>useScroll</code></li>
<li>Animate exit animations with the <code>AnimatePresence</code> component</li>
<li>Create spring-like animations with the <code>useSpring</code> hook</li>
<li>Add drag controls with the <code>useDragControls</code> hook</li>
<li>Animate elements in 3d space with the <code>framer-motion-3d</code> package</li>
</ul>
<p>In a sentence, if you are looking to easily make your React app visually impressive, you owe it to yourself to check out Framer Motion.</p>
<h2 id="heading-want-to-build-a-native-app-use-capacitorjs">Want to Build a Native App? Use Capacitor.js</h2>
<p>It makes sense to consider using React native if you want to build a native app as a React developer. React Native is a great library for building iOS and Android applications with a very similar syntax to any traditional React web projects </p>
<p>There are some libraries which may allow you to share code between your React and React Native projects if you want to build a web and native app, such as React Native web. </p>
<p>However, there is really only one library that will enable you to build true cross platform React apps with a single code base. That library is Capacitor.js. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/Screen-Shot-2022-12-19-at-3.20.19-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Capacitor.js</em></p>
<p>Capacitor.js is a drop-in solution for you to make your web app work on native platforms. In other words, it allows your app to be deployable on the app stores to run on devices natively, but does not require you to change any of your existing code if it has already been designed for the web. </p>
<p>To use Capacitor, you just need to install a couple of packages, <code>@capacitor/core</code> and <code>@capacitor/cli</code>. Capacitor will give you many native APIs to provide all the functionality that a standard native app would have such as push notifications or haptic feedback.</p>
<p>Capacitor allows you to turn your web app into a native app with all the functionality of a native app. Capacitor is one of those impressive solutions that can really change the limits of your application to be able to serve a completely different kind of user and exists in a completely different space if you so choose.</p>
<h2 id="heading-become-a-professional-react-developer">Become a Professional React Developer</h2>
<p>React is hard. You shouldn't have to figure it out yourself.</p>
<p>I've put everything I know about React into a single course, to help you reach your goals in record time:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><strong>Introducing: The React Bootcamp</strong></a></p>
<p><strong>It’s the one course I wish I had when I started learning React.</strong></p>
<p>Click below to try the React Bootcamp for yourself:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a>
<em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The Best Backend as a Service for your React App ]]>
                </title>
                <description>
                    <![CDATA[ If you're building an app on your own or on a budget, you may want to consider using a backend-as-a-service (BaaS). Doing so allows you to focus on the frontend of your application, but still have a full-stack app with a database, authentication, and... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/best-backend-service-react/</link>
                <guid isPermaLink="false">66d03752dcd3a41034854bb6</guid>
                
                    <category>
                        <![CDATA[ backend ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Tue, 29 Nov 2022 22:56:39 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/11/mugshotbot.com_customize_color-pink-description-Create-a-culture-people-want-to-be-part-of-with-Gifcoins-3A-the-easy-to-use-peer-recognition-platform.-hide_watermark-0-image-2683d973-mode-light-pattern-bank_note-theme-two_up-title-Peer-to-p.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you're building an app on your own or on a budget, you may want to consider using a backend-as-a-service (BaaS). Doing so allows you to focus on the frontend of your application, but still have a full-stack app with a database, authentication, and more. </p>
<p>In this guide, we will cover three of the best options for you as a React developer to quickly launch your app using a backend-as-a-service, all while saving time, effort, and costs. </p>
<h2 id="heading-supabase">Supabase</h2>
<p>For many years, Firebase has dominated the backend-as-a-service space. In the past couple of years, however, Supabase has emerged as a great alternative. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-29-at-1.56.30-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Supabase homepage</em></p>
<p>The main benefit of Supabase is that it is <strong>open-source</strong>. In short, Supabase allows you to take your code and deploy it wherever you like. You can build your app, deploy it to Supabase's servers, or you can deploy it to your own hosting service later on. </p>
<p>The great benefit of this is that it helps you avoid <strong>vendor lock-in</strong>. The problem of vendor lock-in emerges if you run into a situation where want to migrate away from the service you are using. For example, if the service's pricing becomes too high or you have fundamental problems with using the service. The problem is that you are "locked-in" and it may be very hard to go elsewhere.</p>
<p>As you'll see with the other two options in this list (Firebase and AWS Amplify), they have some degree of vendor lock-in. In short, it's not easy to migrate away from them. </p>
<p>Supabase, on the other hand, gives you the flexibility to host your project where you like without a difficult migration process. </p>
<p>Supabase gives you a Postgres database and it is compatible with just about every React framework including many other non-React JavaScript libraries. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-29-at-12.44.58-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Supabase-supported JavaScript libraries</em></p>
<p>To start using Supabase with your React app, you will install the <code>supabase-js</code> npm package. </p>
<p>To actually start your Supabase project itself and create your database, you will sign in to Supabase.com. The free tier will give you all of the major features that you need, including a free database, as well as built-in authentication. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-29-at-12.47.11-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Supabase Authentication</em></p>
<p>Supabase authentication includes tons of major social providers like Google and Facebook. </p>
<p>They also offer built-in storage which allows you to store any type of file. This feature would be essential if your application features video or image uploads.</p>
<p>Supabase also supports realtime data via WebSockets, a feature with both Firebase and AWS Amplify offer, as well.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/08/supabase-storage-and-functions.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Supabase storage and functions</em></p>
<p>Supabase offers edge functions, which enable you to write custom code that interacts with with your database. These edge functions may be useful if you want to write some custom logic that the Supabase npm packages don't support or if you want to do something on the server, such as sending an email. </p>
<p>One area where Supabase has an advantage over Firebase is their <strong>full text search</strong> feature. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-29-at-12.51.11-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Supabase full text search</em></p>
<p>If you want to provide search functionality to your app based off of what's stored in your database, this is something that Firebase's Cloud Firestore database simply does not provide.</p>
<p>Supabase's free plan can take you a long way, but if you would like database backups, plus the ability to store additional data, database or storage beyond the free limits you'll need to upgrade to their Pro Plan (which is $25 per month per project). Unlike Firebase and AWS, there is a big jump in pricing if you want something more than the free limit provides. </p>
<p>With that being said, the Supabase pro tier is very generous. When you're ready to push your app to the world, it will supply virtually everything that you need from a backend for just $25 a month.</p>
<h2 id="heading-firebase">Firebase</h2>
<p>Firebase cannot be beat in terms of its longevity and what it offers. </p>
<p>Firebase has been around for 10 years at this point and offers the most products out of any backend solution. </p>
<p>It's a very sophisticated all-in-one service, with its own NoSQL database storage, authentication with every kind of social provider imaginable, along with some features that Supabase does not have, such as Crash Analytics, performance insights, A/B testing, push notifications and much more. </p>
<p>If you really want the most complete option, you should seriously consider Firebase. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/08/firebase-homepage.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Firebase homepage and services</em></p>
<p>Firebase is similarly easy to get set up with. You can create an account a many free projects at Firebase's website. </p>
<p>To create a database or dedicated storage requires only the click of a button. Firebase is similarly unmatched at providing a very convenient dashboard to interface with all of your individual products, such as your database. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-29-at-12.59.44-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Firebase Cloud Firestore</em></p>
<p>All these benefits of Firebase can be a potential downside. Firebase truly offers so much that it can be a little bit overwhelming to figure out what you should use and what you shouldn't to get up and running.</p>
<p>My recommendation for your React app is to first use the Cloud FireStore database, authentication and storage, and add on the Firebase functions service if you need to provide custom logic on your server. Only then do you need to look at their other options. </p>
<p>Unlike Supabase, but similar to AWS Amplify, Firebase includes built-in hosting. There is no need to look elsewhere for a hosting service or any other custom solution.</p>
<p>The real downside of Firebase, as I mentioned earlier, is their vendor lock-in. Once you build your app with Firebase, it may be quite difficult to migrate to another platform. With that being said, many many companies have built their entire livelihood on Firebase.</p>
<p>The cost of using Firebase is a bit more challenging to calculate. Fortunately, Firebase provides a convenient calculator that will give you a much better idea, based off of your app's resource usage. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-29-at-1.03.29-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Firebase's plan calculator</em></p>
<p>Their plan is generous for the free user and you can start using virtually every service for free. You will only have to start paying once you exceed those limits.</p>
<p>Firebase is the closest to an all-in-one service to serve as the backend of your app. If you are intent on building your app quickly, with as little time spent on choosing and managing services as possible, you can't go wrong with Firebase.</p>
<h2 id="heading-aws-amplify">AWS Amplify</h2>
<p>The last contender is AWS amplify, which is often overlooked, but shouldn't be. </p>
<p>AWS is notoriously difficult to navigate at times, but AWS Amplify was made as an exception to this rule. AWS Amplify not only provides an impressive database, storage, plus realtime experience for JavaScript developers, but comes with a component library, Amplify UI. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/08/aws-amplify.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>AWS Amplify and Amplify UI</em></p>
<p>For example, instead of having to create your own authentication component, Amplify UI provides its own for you out of the box. </p>
<p>In short, AWS Amplify gives you virtually all of the tools of Firebase, along with premium, pre-made components that are already integrated with your AWS backend. </p>
<p>One additional benefit of using AWS Amplify over Firebase and Supabase is that it's most likely going to be the least expensive overall. </p>
<p>AWS pricing is one of the lowest when it comes to infrastructure businesses. In many cases, AWS will give you startup credits if you're using AWS for the first time. If so, the cost of your app may be next to nothing. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-29-at-1.11.01-PM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Amplify Pricing</em></p>
<p>The large caveat to using AWS Amplify is that it relies on GraphQL. If you're not familiar with GraphQL this may be a sticking point for you. It does have a REST API alternative. The REST option, however, is not nearly as featureful and doesn't provide the same bonuses, such as realtime data with subscriptions.</p>
<p>Another downside to using AWS amplify is that you can write custom resolvers to interact with your database and other AWS services, but they are not written in JavaScript. Instead, the Amplify console uses what's known as the "Apache Velocity Template Language" or VTL. Be aware that writing custom server code could be quite difficult if you need to write custom business logic.</p>
<p>AWS Amplify has an enormous offering of integrated services and allows you to tap into so many AWS products, such as DynamoDB, S3 and ElasticSearch. It has been built to support every imaginable developer need you might have. It goes so far as to enable you to do things like like audio-to-text transcription and extended reality (XR) integrations. </p>
<p>Amplify is definitely worth checking out if you're looking to find the most cost effective service that does not sacrifice any features that Firebase has. Amplify is also a good choice if you're comfortable with GraphQL and know the AWS ecosystem well.</p>
<h2 id="heading-thanks-for-reading">Thanks for reading!</h2>
<p>Hopefully you're now well-equipped to choose the best backend as a service tool for your React project.</p>
<h2 id="heading-become-a-professional-react-developer">Become a Professional React Developer</h2>
<p>React is hard. You shouldn't have to figure it out yourself.</p>
<p>I've put everything I know about React into a single course, to help you reach your goals in record time:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><strong>Introducing: The React Bootcamp</strong></a></p>
<p><strong>It’s the one course I wish I had when I started learning React.</strong></p>
<p>Click below to try the React Bootcamp for yourself:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a>
<em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
