<?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[ Scott M - 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[ Scott M - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 27 Aug 2026 22:36:57 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/ohmycrawl/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Common React Mistakes to Avoid ]]>
                </title>
                <description>
                    <![CDATA[ React is a highly popular and powerful JavaScript library for user interface development. Its component-based architecture, combined with its declarative nature, is one of the primary reasons it works ]]>
                </description>
                <link>https://www.freecodecamp.org/news/react-common-mistakes/</link>
                <guid isPermaLink="false">66d460f651f567b42d9f84ab</guid>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Scott M ]]>
                </dc:creator>
                <pubDate>Tue, 06 Aug 2024 22:19:05 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/08/react-mistakes.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>React is a highly popular and powerful JavaScript library for user interface development. Its component-based architecture, combined with its declarative nature, is one of the primary reasons it works well for both small and large-scale applications.</p>
<p>But like with any technology, there are pitfalls that you can fall into when you're writing React code if you're not careful.</p>
<p>In this article, we will discuss these common mistakes and I'll provide you with best practices to avoid them. This will help you keep your React projects efficient, maintainable, and scalable.</p>
<h2 id="heading-1-mistakes-in-key-props-usage">1. Mistakes in Key Props Usage</h2>
<p>One of the most common mistakes when using React involves the key prop. There are several scenarios where key props are used, with lists being the most common.</p>
<p>The key prop is crucial because it helps React track which items have changed, been added, or removed. If they are not correctly set, React's diffing algorithm can become inefficient, leading to performance issues and bugs.</p>
<p><strong>Best Practice:</strong> Always pass a stable and unique key for the items in a list. If possible, use unique IDs from your data instead of array indices as keys.</p>
<pre><code class="language-plaintext">const ItemList = ({ items }) =&gt; (
  &lt;ul&gt;
    {items.map(item =&gt; (
      &lt;li key={item.id}&gt;{item.name}&lt;/li&gt;
    ))}
  &lt;/ul&gt;
);
</code></pre>
<p>In the above code snippet, each item in the list has a key with <code>item.id</code>. This ensures that every list item is uniquely identifiable, helping React render more efficiently and reduce unnecessary renders.</p>
<p>For more tips on optimizing performance, check out this article on <a href="https://www.freecodecamp.org/news/caching-in-react/">caching in React</a>.</p>
<h2 id="heading-2-ignoring-the-virtual-dom">2. Ignoring the Virtual DOM</h2>
<p>Some developers mistakenly believe that the role of the Virtual DOM means they need to update the DOM themselves. This goes against how React works and can result in unpredictability and bugs.</p>
<h3 id="heading-what-is-the-virtual-dom">What is the Virtual DOM?</h3>
<p>For those new to React, the Virtual DOM is an in-memory representation of the real DOM. It allows React to update the UI efficiently by minimizing direct manipulations of the actual DOM. React compares the new Virtual DOM with the previous one and updates only the necessary parts of the real DOM.</p>
<p>Developers might assume they need to synchronize the Virtual DOM with the real DOM due to experiences with other libraries or frameworks.</p>
<p><strong>Best Practice:</strong> Always let React handle the DOM. If you must interact directly with the DOM, use refs.</p>
<pre><code class="language-plaintext">const ItemList = ({ items }) =&gt; (
  &lt;ul&gt;
    {items.map(item =&gt; (
      &lt;li key={item.id}&gt;{item.name}&lt;/li&gt;
    ))}
  &lt;/ul&gt;
);
</code></pre>
<p><strong>Explanation:</strong></p>
<p>Using a unique identifier from the data, such as <code>item.id</code>, ensures that each key is unique and stable. This allows React to efficiently determine which items have changed, been added, or removed. It helps React's reconciliation algorithm to update the UI efficiently and prevents bugs related to item reordering or deletion.</p>
<h2 id="heading-3-overusing-state">3. Overusing State</h2>
<p>State management is crucial in React, but excessive state usage can make a component complex and difficult to maintain. Any change in state triggers a re-render, which can be expensive if not handled properly.</p>
<p><strong>Best Practice:</strong> Minimize the use of state and lift state only when necessary. For global state, use contexts or state management libraries like Redux.</p>
<pre><code class="language-plaintext">import React, { useState } from 'react';

const MyComponent = () =&gt; {
  const [count, setCount] = useState(0);
  const [name, setName] = useState(''); // Additional state

  const handleIncrement = () =&gt; setCount(count + 1);
  const handleNameChange = (e) =&gt; setName(e.target.value);

  return (
    &lt;div&gt;
      &lt;p&gt;Count: {count}&lt;/p&gt;
      &lt;button onClick={handleIncrement}&gt;Increment&lt;/button&gt;
      &lt;input
        type="text"
        value={name}
        onChange={handleNameChange}
        placeholder="Enter name"
      /&gt;
    &lt;/div&gt;
  );
};
</code></pre>
<p>In the above example, the <code>useState</code> hook is used to maintain a simple count state. When the button is pressed, it displays and increments the count, demonstrating a very basic use of state.</p>
<h2 id="heading-4-forgetting-to-clean-up-effects">4. Forgetting to Clean Up Effects</h2>
<p>When using the useEffect hook, it is essential to clean up side effects to prevent memory leaks and other unintended behaviors. Side effects might include setting up subscriptions, timers, or event listeners that need to be cleared when the component unmounts or when the effect dependencies change.</p>
<p><strong>Best Practice:</strong> Always return a cleanup function from your effect when setting up side effects that need to be cleared.</p>
<p>Example without Cleanup:</p>
<pre><code class="language-plaintext">const Timer = () =&gt; {
  const [time, setTime] = React.useState(0);

  React.useEffect(() =&gt; {
    const intervalId = setInterval(() =&gt; {
      setTime(prevTime =&gt; prevTime + 1);
    }, 1000);
    // No cleanup function provided here
  }, []);

  return &lt;div&gt;Time: {time}s&lt;/div&gt;;
};
</code></pre>
<p>In the example above, a timer is set up with <code>setInterval</code>, but no cleanup function is provided to clear the interval when the component unmounts. This can lead to memory leaks.</p>
<p><strong>Correct</strong>: Cleanup with <code>useEffect</code>:</p>
<pre><code class="language-plaintext">const Timer = () =&gt; {
  const [time, setTime] = React.useState(0);

  React.useEffect(() =&gt; {
    const intervalId = setInterval(() =&gt; {
      setTime(prevTime =&gt; prevTime + 1);
    }, 1000);

    // Cleanup function to clear the interval
    return () =&gt; clearInterval(intervalId);
  }, []);

  return &lt;div&gt;Time: {time}s&lt;/div&gt;;
};
</code></pre>
<p>In this corrected example, a cleanup function is provided to clear the interval when the component unmounts, preventing potential memory leaks.</p>
<h2 id="heading-5-ignoring-performance">5. Ignoring Performance</h2>
<p>A React application can encounter serious performance issues, such as excessive re-renders and heavy calculations during render.</p>
<p><strong>Best Practice:</strong> Memoize components and values using <code>React.memo</code>, <code>useMemo</code>, and <code>useCallback</code> for improved performance.</p>
<pre><code class="language-plaintext">const MemoizedComponent = React.memo(({ data }) =&gt; {
  return &lt;div&gt;{data}&lt;/div&gt;;
});
</code></pre>
<p>This example uses <code>React.memo</code> to memoize a functional component, preventing it from re-rendering unnecessarily when the <code>data</code> prop hasn't changed.</p>
<h2 id="heading-6-overusing-the-context-api">6. Overusing the Context API</h2>
<p>The Context API is very handy for passing data through your component tree without prop drilling. But it's often overused, leading to performance issues.</p>
<p><strong>Best Practice:</strong> Avoid using context for frequently changing values. Mainly use it for static values or rare updates.</p>
<pre><code class="language-plaintext">const ThemeContext = React.createContext('light');

const ThemedComponent = () =&gt; {
  const theme = useContext(ThemeContext);
  return &lt;div className={theme}&gt;Themed Component&lt;/div&gt;;
};
</code></pre>
<p>In the above example, <code>ThemeContext</code> is initialized with the default value <code>'light'</code>. The <code>ThemedComponent</code> uses the <code>useContext</code> hook to get the actual value of the theme.</p>
<h2 id="heading-7-not-handling-errors-properly">7. Not Handling Errors Properly</h2>
<p>One important feature of React is error boundaries. They catch and handle errors in the component tree. Without them, unhandled errors may eventually crash the entire application.</p>
<p><strong>Best Practice:</strong> Implement error boundaries using <code>componentDidCatch</code> or <code>ErrorBoundary</code> components.</p>
<pre><code class="language-plaintext">const UserProfile = ({ userId }) =&gt; {
  const [user, setUser] = React.useState(null);
  const [error, setError] = React.useState(null);

  React.useEffect(() =&gt; {
    fetch(`/api/users/${userId}`)
      .then(response =&gt; {
        if (!response.ok) {
          throw new Error('Network response was not ok');
        }
        return response.json();
      })
      .then(data =&gt; setUser(data))
      .catch(err =&gt; setError(err.message));
  }, [userId]);

  if (error) {
    return &lt;div&gt;Error: {error}&lt;/div&gt;;
  }

  if (!user) {
    return &lt;div&gt;Loading...&lt;/div&gt;;
  }

  return &lt;div&gt;{user.name}&lt;/div&gt;;
};
</code></pre>
<p>By adding error handling, we catch any issues with the API request and display an appropriate error message.</p>
<p>This approach improves the robustness of the component, providing users with feedback in case of an error and ensuring the application remains functional even when unexpected issues occur.</p>
<h2 id="heading-8-failing-to-keep-components-pure">8. Failing to Keep Components Pure</h2>
<p>React components should always be pure functions of their props. Impure components depend on external states and side effects, making the system unpredictable.</p>
<p><strong>Best Practice:</strong> Ensure that your components are pure and that their output depends entirely on their props.</p>
<pre><code class="language-plaintext">const MyComponent = ({ name }) =&gt; {
  return &lt;div&gt;{name}&lt;/div&gt;;
};
</code></pre>
<p>This functional component is pure because it only depends on the <code>name</code> prop to render its output.</p>
<h2 id="heading-9-not-using-react-developer-tools">9. Not Using React Developer Tools</h2>
<p>React Developer Tools is a simple yet essential extension for debugging and optimizing the performance of a React application. Development can become more complicated if you don't use this helpful toolkit.</p>
<p><strong>Best Practice:</strong> Install and use React Developer Tools regularly to inspect component hierarchies, state, and props.</p>
<h2 id="heading-10-ignoring-seo-best-practices">10. Ignoring SEO Best Practices</h2>
<p>SEO is an important aspect of any web application, and this holds true for React applications as well. Many developers overlook SEO, leading to poor search engine rankings and reduced visibility.</p>
<p>Here are some of the most common React SEO mistakes:</p>
<div class="embed-wrapper"><iframe width="560" height="315" src="https://www.youtube.com/embed/tIQv8oIn3g4" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>

<p>Wondering how to implement the React SEO Best Practices? Good news, I made a follow up video:</p>
<div class="embed-wrapper"><iframe width="560" height="315" src="https://www.youtube.com/embed/xAFzD1ckPXs" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>

<p><strong>Best Practices:</strong> If video is not your thing, here are the key points to remember:</p>
<ul>
<li><p>Always <a href="https://www.freecodecamp.org/news/server-side-rendering-javascript/">render your content server-side</a>: Google has publicly stated to avoid Client-Side Rendering (CSR).</p>
</li>
<li><p>Ensure unique URLs for different pages: Since React is a Single Page Application (SPA), always render different URLs for different pages. For example, if you have 5 landing pages, make sure you render 5 unique URLs.</p>
</li>
<li><p>Ensure unique metadata for each page: As a bonus tip, use <a href="https://www.freecodecamp.org/news/react-helmet-examples/">React Helmet</a> to ensure every single page has unique metadata.</p>
</li>
<li><p>Internally link your website: Surprisingly, many developers completely ignore this. Make sure to add internal links to improve navigation and SEO.</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In conclusion, avoiding these common React mistakes can greatly improve the performance and maintainability of your applications.</p>
<p>If you're interested in learning more about my work or need help with React or Next.js development, check out <a href="https://www.hirenext.dev/">hirenext.dev</a>. Alternatively you can keep up with my blog <a href="https://www.ohmycrawl.com/">OhMyCrawl</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Choose a CMS – Tips for Content Management Systems ]]>
                </title>
                <description>
                    <![CDATA[ If you're an entrepreneur or a developer, chances are you'll work with a content management systems (CMS) at some point. And knowing how to analyze the many features of the CMS options out there is im ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-choose-a-cms/</link>
                <guid isPermaLink="false">66d460f2ffe6b1f641b5fa7f</guid>
                
                    <category>
                        <![CDATA[ cms ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Website design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Scott M ]]>
                </dc:creator>
                <pubDate>Thu, 01 Jun 2023 23:06:02 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/06/how-to-choose-cms.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you're an entrepreneur or a developer, chances are you'll work with a content management systems (CMS) at some point. And knowing how to analyze the many features of the CMS options out there is important when choosing the right one for your use case.</p>
<p>In this article, I'll explain why CMSs exist, the problems they help solve, and I'll also offer helpful guidance in choosing the right CMS for your needs.</p>
<h2 id="heading-what-is-a-cms">What is a CMS?</h2>
<p>You can think of a CMS as an extremely user-friendly database for your website’s content.</p>
<p>A CMS provides an intuitive interface that allows website owners and content creators to manage a website's content without requiring advanced technical skills.</p>
<p>As an example, think about it from the perspective of someone who wants to own a blog, but doesn’t know anything about web development. It would be very difficult, if not impossible, for this person to modify the source code of the web site in order to add a new article to the blog.</p>
<p>This is where a CMS comes in. The CMS is linked to the owner’s website, and the site has built in code that pulls data from the CMS and automatically publishes this data on the site. In this example, the data could be a new blog article and image.</p>
<h2 id="heading-headless-cms-vs-traditional-cms">Headless CMS vs Traditional CMS</h2>
<p>You may have heard the term “headless CMS” floating around, and wondered what that was all about. Nowadays, CMSs come in two flavors; a traditional CMS, and a headless CMS. Let’s take a look at a few definitions to get a better grasp of each:</p>
<h3 id="heading-what-is-a-traditional-cms">What is a Traditional CMS?</h3>
<p>A traditional CMS is a complete website management system that not only stores your content in a user-friendly database, but also offers a front end, usually a WYSIWYG style editor to build out your actual web page.</p>
<p>The front-end UI designer and backend storage system are unified in one intuitive interface. Wordpress is a famous example of a traditional CMS.</p>
<h3 id="heading-what-is-a-headless-cms">What is a Headless CMS?</h3>
<p>A headless CMS is similar to the traditional CMS, but without the front-end WYSIWYG editor to build your site. If you think of your actual webpage as the “head”, and your content as the “body”, then this starts to make sense.</p>
<p>A headless CMS is totally independent of your site’s design, and you can typically use any framework of choice and connect it to the headless CMS. The headless CMS acts similar to a backend database, but is tailor-made for handling typically used website content like images and rich text.</p>
<h2 id="heading-when-do-i-need-a-cms">When Do I Need a CMS?</h2>
<p>Before concerning yourself with choosing the right CMS for your needs, it is essential to understand whether you actually need one. CMSs are designed to streamline the process of creating, editing, and managing digital content, primarily for websites.</p>
<p>If you’re wondering whether you should consider a CMS, ask yourself the following questions:</p>
<ol>
<li><p>Does the website require frequent content updates, such as articles or product listings?</p>
</li>
<li><p>Will there be multiple content authors collaborating on the website's content?</p>
</li>
<li><p>Does the website require flexible content structuring and organization to accommodate future changes?</p>
</li>
</ol>
<p>If you answered yes to one of these questions, there’s a good chance that your project would benefit from the features offered by a good CMS.</p>
<h2 id="heading-cms-integration-and-compatibility">CMS Integration and Compatibility</h2>
<p>It’s important to consider ease of integration with your chosen system or framework. You may be considering adding some functionality to your site such as an e-commerce system or customer relationship management (CRM) software. Or you may just be starting a new project from scratch.</p>
<p>Either way, it is crucial to ensure that the CMS you select can seamlessly integrate with these systems.</p>
<p>Most frameworks, such as Next.js, Gatsby or Astro, will offer a list of official CMS plugins that streamline the process of integration. Of course, a CMS can be added to any project without an official plugin by utilizing the API from your CMS of choice, and coding everything manually.</p>
<p>But it’s usually wise to look for a CMS that is supported by your framework, as it takes much of the heavy lifting out of the equation and allows you to focus on other pressing concerns.</p>
<p>For example my blog has a list of the <a href="https://www.ohmycrawl.com/nextjs/best-cms/">best CMS for Next.js</a> to choose from. Most frameworks have a number of CMSs that are compatible and created by 3rd party developers.</p>
<p>When searching for a CMS with seamless integration and compatibility, look to your framework’s official docs for guidance, which should tell you what public libraries are available.</p>
<h2 id="heading-cms-features-to-consider">CMS Features to Consider</h2>
<p>When evaluating CMS options, do some research and testing rather than going for the first option that pops up. While the specific requirements may vary depending on your project, here are some fundamental features to look for:</p>
<ol>
<li><p><strong>User-Friendliness:</strong> The CMS should have an intuitive and user-friendly interface, enabling non-technical users to manage and update content easily.</p>
</li>
<li><p><strong>Content Organization:</strong> Effective content organization is crucial for a CMS. Look for features such as categorization, tagging, and metadata management to ensure your content is easily searchable and conveniently organized.</p>
</li>
<li><p><strong>SEO Optimization:</strong> Ensure the CMS supports essential SEO features, such as image optimization, full-featured rich text editors, and friendly URLs.</p>
</li>
</ol>
<h2 id="heading-common-cms-pitfalls">Common CMS Pitfalls</h2>
<p>There are a few potential pitfalls you should consider, because utilizing a CMS doesn’t always live up to expectations. Here are a few common challenges:</p>
<ol>
<li><p><strong>Overwhelming Complexity:</strong> This may seem oxymoronic, considering my earlier statement that CMSs are supposed to simplify things. But everyone is different, and one CMS may not suit your taste as much as the next person. It’s a good idea to create an account and take a look around, maybe even create some content, just to get a feel for whether the CMS is right for you.</p>
</li>
<li><p><strong>Hidden Costs:</strong> Many CMSs claim they are free. But almost all of them begin charging when you reach a certain threshold of traffic or storage capacity. It’s important that you do your research, and ensure that you’re considering whether your project will venture into the realm of “paid service” sooner than you expected.</p>
</li>
<li><p><strong>Limited Support and Documentation:</strong> When encountering issues or needing assistance, reliable support and comprehensive documentation is paramount. Ensure that the CMS you choose has an active community, official support channels, and extensive documentation or user guides. This support network can be invaluable in troubleshooting problems and learning how to make the most of the CMS's features.</p>
</li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Choosing the right CMS is an important decision that can impact your website's performance, scalability, and ease of management. By understanding the purpose of a CMS and evaluating your specific needs, you can make an informed decision that aligns with your goals.</p>
<p>Ultimately, a CMS should empower you to efficiently create, manage, and update content, allowing you to focus on delivering a compelling user experience. At the end of the day, meaningful content is the goal, and a CMS should be a helpful hand that guides you through the process.</p>
<p>Hope you enjoyed the post. If you want to learn more about CMSs and SEO in general checkout <a href="https://www.ohmycrawl.com/">OhMyCrawl</a>. If you want to follow along with one of my side projects, checkout my latest site <a href="http://trustingeeks.com">Trust In Geeks</a> to follow my journey.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Caching in React – How to Use the useMemo and useCallback Hooks ]]>
                </title>
                <description>
                    <![CDATA[ As you become more proficient at coding in React, performance will become a major focal point in your development process. As with any tool or programming methodology, caching plays a huge role when i ]]>
                </description>
                <link>https://www.freecodecamp.org/news/caching-in-react/</link>
                <guid isPermaLink="false">66d460eea326133d12440a76</guid>
                
                    <category>
                        <![CDATA[ caching ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ react hooks ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Scott M ]]>
                </dc:creator>
                <pubDate>Mon, 15 May 2023 18:39:25 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/05/caching-react.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>As you become more proficient at coding in React, performance will become a major focal point in your development process.</p>
<p>As with any tool or programming methodology, caching plays a huge role when it comes to optimizing React applications.</p>
<p>Caching in React typically goes by the term <em>memoization</em>. It's used to improve performance by reducing the amount of times a component renders due to state or prop mutations.</p>
<p>React provides two APIs for caching: useMemo and useCallback. useCallback is a hook that memoizes a function, while useMemo is a hook that memoizes a value. These two hooks are often used in conjunction with the Context API to further improve efficiency.</p>
<p>Here’s a basic list of topics we’ll be covering in this article:</p>
<ol>
<li><p>React caching default behavior.</p>
</li>
<li><p>The useMemo hook.</p>
</li>
<li><p>The useCallback hook.</p>
</li>
</ol>
<p>In order to follow along, you'll need a decent understanding of React and stateful components.</p>
<h2 id="heading-default-caching-behavior-in-react">Default Caching Behavior in React</h2>
<p>By default, <a href="https://www.ohmycrawl.com/react/">React</a> uses a technique called “shallow comparison” to determine whether a component should be re-rendered. This basically means that if the props or state of a component haven’t changed, React will assume that the output of the component hasn’t changed either and won’t re-render it.</p>
<p>While this default caching behavior is very effective by itself, it isn’t always enough to optimize complex components that require advanced state management.</p>
<p>In order to achieve more control over your component’s caching and rendering behavior, React offers the <strong>useMemo</strong> and <strong>useCallback</strong> hooks.</p>
<h2 id="heading-caching-in-react-with-the-usememo-hook">Caching in React with the useMemo Hook</h2>
<p>useMemo is useful when you need to do an expensive computation to retrieve a value, and you want to ensure that the computation is only performed when necessary. By memoizing the value using useMemo, you can ensure that the value is only computed when its dependencies change.</p>
<p>In a React component, you may have multiple properties that make up your state. If a piece of state changes that has nothing to do with our expensive value, why recompute it if it hasn’t changed?</p>
<p>Here’s an example code block reflecting a basic useMemo implementation:</p>
<pre><code class="language-plaintext">react
import React, { useState, useMemo } from 'react';
function Example() {
const [txt, setTxt] = useState(“Some text”);
const [a, setA] = useState(0);
const [b, setB] = useState(0);
const sum = useMemo(() =&gt; {
console.log('Computing sum...');
return a + b;
}, [a, b]);
return (
&lt;div&gt;
&lt;p&gt;Text: {txt}&lt;/p&gt;
&lt;p&gt;a: {a}&lt;/p&gt;
&lt;p&gt;b: {b}&lt;/p&gt;
&lt;p&gt;sum: {sum}&lt;/p&gt;
&lt;button onClick={() =&gt; setTxt(“New Text!”)}&gt;Set Text&lt;/button&gt;
&lt;button onClick={() =&gt; setA(a + 1)}&gt;Increment a&lt;/button&gt;
&lt;button onClick={() =&gt; setB(b + 1)}&gt;Increment b&lt;/button&gt;
&lt;/div&gt;
);
}
</code></pre>
<p>In our Example component above, assume the <strong>sum()</strong> function performs an expensive computation. If the <strong>txt</strong> state is updated, React is going to re-render our component, but because we memoized the returned value of sum, this function will not run again at this time.</p>
<p>The only time the <strong>sum()</strong> function will run is if either the <strong>a</strong> or <strong>b</strong> state has been mutated (changed). This is an excellent improvement upon the default behavior, which will rerun this method upon each re-render.</p>
<h2 id="heading-caching-in-react-with-the-usecallback-hook">Caching in React with the useCallback Hook</h2>
<p>useCallback is useful when you need to pass a function as a prop to a child component, and you want to ensure that the function reference does not change unnecessarily. By memoizing the function using useCallback, you can ensure that the function reference remains the same as long as its dependencies do not change.</p>
<p>Without getting too heavy into JavaScript function references, let’s just take a look at how they can affect the rendering of your React app. When a function reference changes, any child components that receive the function as a prop will re-render, even if the function logic itself has not changed.</p>
<p>This is because, as we already mentioned, React does a shallow comparison of prop values to determine whether a component should re-render, and a new function reference will always be considered a different value than the previous one.</p>
<p>In other words, the simple act of redeclaring a function (even the same exact function), causes the reference to change, and will cause the child component that receives the function as a prop to unnecessarily re-render.</p>
<p>Here’s an example code block reflecting a basic useCallback implementation:</p>
<pre><code class="language-plaintext">react
import React, { useState, useCallback } from 'react';
function ChildComponent({ onClick }) {
console.log('ChildComponent is rendered');
return (
&lt;button onClick={onClick}&gt;Click me&lt;/button&gt;
);
}
function Example() {
const [count, setCount] = useState(0);
const [txt, setTxt] = useState(“Some text…”);
const incrementCount = useCallback(() =&gt; {
setCount(prevCount =&gt; prevCount + 1);
}, [setCount]);
return (
&lt;div&gt;
&lt;p&gt;Text: {txt}&lt;/p&gt;
&lt;p&gt;Count: {count}&lt;/p&gt;
&lt;button onClick={setTxt}&gt;Set Text&lt;/button&gt;
&lt;button onClick={setCount}&gt;Increment&lt;/button&gt;
&lt;ChildComponent onClick={incrementCount} /&gt;
&lt;/div&gt;
);
}
</code></pre>
<p>As you can see in the above example, we pass the <strong>incrementCount</strong> method instead of the <strong>setCount</strong> method to the child component. This is because <strong>incrementCount</strong> is memoized, and when we run our <strong>setTxt</strong> method, it won’t cause the child component to unnecessarily re-render.</p>
<p>The only way our child component will re-render in this example is if the <strong>setCount</strong> method runs, because we passed it as a dependency parameter to our <strong>useCallback</strong> memoization.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Caching is an important technique for optimizing React applications. By reducing unnecessary re-renders, caching can help to improve the performance and efficiency of your application.</p>
<p>React provides a default caching behavior by using a virtual DOM to compare changes in state and props, and only updating components after a shallow comparison reflects changes. This is a great optimization technique that’s sufficient in many scenarios, but sometimes more fine-grained control is desired.</p>
<p>The useMemo and useCallback hooks were created to achieve this fine-grained control.</p>
<p>useMemo is used to memoize the <em>results</em> of a function call, and is useful when the function is expensive to compute and the result does not change often.</p>
<p>useCallback is used to memoize the actual reference of a function rather than the returned value, and is used when the function is passed as a prop to child components that might cause unnecessary re-renders.</p>
<p>Want to learn more? To learn more check out the <a href="https://www.ohmycrawl.com/blog/">OhMyCrawl Blog</a> for more programming tips for SEO.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Server Side Rendering in JavaScript – SSR vs CSR Explained ]]>
                </title>
                <description>
                    <![CDATA[ The concept of Server Side Rendering (SSR) is often misunderstood. So my aim in this article is to bring clarity to this process and how it works. Here's what we'll cover in this guide: What is serve ]]>
                </description>
                <link>https://www.freecodecamp.org/news/server-side-rendering-javascript/</link>
                <guid isPermaLink="false">66d460f951f567b42d9f84b3</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Scott M ]]>
                </dc:creator>
                <pubDate>Mon, 24 Apr 2023 22:12:31 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/04/pexels-steve-johnson-12939554.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>The concept of Server Side Rendering (SSR) is often misunderstood. So my aim in this article is to bring clarity to this process and how it works.</p>
<p>Here's what we'll cover in this guide:</p>
<ol>
<li><p>What is server side rendering? What are its pros and cons when compared to other rendering methods such as Client Site Rendering (CSR)?</p>
</li>
<li><p>How do you know if a site is rendered using SSR?</p>
</li>
<li><p>How to use SSR, and things to keep in mind when choosing an SSR framework.</p>
</li>
<li><p>How to leverage SSR to improve performance.</p>
</li>
</ol>
<p>We’ll cover each of these items in depth, so that by the end of this tutorial you have a firm grasp of server side rendering and how it fits into the ever-changing world of web development.</p>
<p>We should also look at two key terms we’ll be using throughout, and what they mean:</p>
<ol>
<li><p>HTML – Hyper Text Markup Language. HTML isn’t technically code, it’s simply a markup language that structures your content on a web page.</p>
</li>
<li><p>DOM – Document Object Model. The DOM is an actual model of your HTML, made up of objects. It has an API interface which allows you to modify it, and in-turn modify the HTML.</p>
</li>
</ol>
<p>It’s important to understand the difference between HTML and the DOM. When you're reading through documentation it's easy to become confused and misinterpret the two.</p>
<h2 id="heading-what-is-server-side-rendering-ssr">What is Server Side Rendering (SSR)?</h2>
<p>SSR is when you render your website's HTML on the server. This is as opposed to Client Side Rendering (CSR) when your website renders HTML in the browser by manipulating the DOM with JavaScript.</p>
<h2 id="heading-how-to-check-for-ssr">How to Check For SSR</h2>
<p>There are certain times when you'll want to check whether a site is using <a href="https://www.ohmycrawl.com/check-server-side-rendering/">server side rendering</a>. For instance, both developers and SEO professionals often need this information to help troubleshoot and optimize technical SEO issues.</p>
<p>We'll discuss a few techniques commonly used to determine this.</p>
<h3 id="heading-check-the-page-source">Check the page source</h3>
<p>An easy way to determine if a site is using SSR is to view the page source.</p>
<p>If the HTML code is complete with all the content, including the main body, images, text, and so on, the site is likely using SSR.</p>
<p>On the other hand, if the HTML code is bare-bones, then it requires JavaScript to render the content. In this case, it's probably not using server side rendering.</p>
<p>The first step is to right click in Chrome or your favorite web browser:</p>
<img src="https://www.freecodecamp.org/news/content/images/2023/04/Capto_Capture-2023-04-24_05-33-39_PM.png" alt="Image" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><em>Right click 'view page source'</em></p>
<p>Once you are viewing the source code, you'll be able to easily search for content elements, for example you'll bee able to find <code>&lt;p&gt;</code> , <code>&lt;h1&gt;</code>, and so on.</p>
<p>If you can see them here, more then likely they are rendering server side:</p>
<img src="https://www.freecodecamp.org/news/content/images/2024/04/rendering-server-side.png" alt="Image" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><em>Anything you see here is rendering sever side</em></p>
<p>Check Google Cache</p>
<p>An easy way to determine if your content is rendering server side is to check the Google Cache.</p>
<p>Simply type in the URL you want to inspect like this with the <code>site:</code> operator into Google.</p>
<p>For example below I typed in <code>site:[https://www.freecodecamp.org/news/](https://www.freecodecamp.org/news/)</code> then selected '<em>Cached</em>':</p>
<img src="https://www.freecodecamp.org/news/content/images/2023/04/Capto_Capture-2023-04-24_05-36-42_PM.png" alt="Image" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><em>type in your URL into Google, then select 'Cached'</em></p>
<p>Generally speaking, anything you can visually see is server side rendering. If it's rendering with Javascript, more than likely you won't be able to see it:</p>
<img src="https://www.freecodecamp.org/news/content/images/2023/04/Capto_Annotation.png" alt="Image" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><em>Anything you see here most likely renders Serverside</em></p>
<h3 id="heading-bonus-tip-disable-javascript">Bonus Tip: Disable JavaScript</h3>
<p>You can also test if a site is using SSR by disabling JavaScript on your browser. If the website's content is still visible without JavaScript, it is likely using SSR. If the website appears blank, it is not using SSR.</p>
<p>In this example here, we can clearly see Airbnb is not leveraging server side rendering on their homepage:</p>
<img src="https://www.freecodecamp.org/news/content/images/2024/04/visual-representation.png" alt="Image" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p>And here's a pretty good visual representation if you don’t quite get the concept yet:</p>
<div class="embed-wrapper"><iframe width="560" height="315" src="https://www.youtube.com/embed/_ojqh9G4c28" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>

<h2 id="heading-ssr-vs-csr">SSR vs CSR</h2>
<p>Let's break down the different processes in client side and server side rendering, followed by the advantages and disadvantages of each one.</p>
<h3 id="heading-how-ssr-works">How SSR Works</h3>
<ol>
<li><p>An HTTP request is made to the server.</p>
</li>
<li><p>The server receives the request, and processes all (or most of) the necessary code right then and there.</p>
</li>
<li><p>The end result is a fully formed and easily consumed HTML page that can be sent to the client’s browser via the server’s response.</p>
</li>
</ol>
<p>This is a fairly simple concept on the surface, but things can get pretty complicated when considering how to include interactive components on the client that require JavaScript. We’ll touch on that later – first let’s check out what happens when you request a CSR web app.</p>
<h3 id="heading-how-csr-works">How CSR Works</h3>
<ol>
<li><p>An HTTP request is made to the server.</p>
</li>
<li><p>The server receives the request, and responds by sending an empty HTML shell to the client along with a bunch of bundled JavaScript.</p>
</li>
<li><p>The client receives the empty HTML shell, and proceeds to process all of the JavaScript.</p>
</li>
<li><p>The JavaScript modifies the DOM extensively, which renders the final HTML for the end user.</p>
</li>
</ol>
<p>To put this in simplified language, client side rendering is when your website or web app renders into HTML in the browser by processing JavaScript, rather than on the server using whatever the backend framework of choice is.</p>
<p>Next we’ll take a look at the strengths and weaknesses of each style of rendering.</p>
<h2 id="heading-benefits-of-ssr">Benefits of SSR</h2>
<p>The main benefit of server side rendering is page load speed. Page load speed is an important metric for user experience, and subsequently an important aspect of technical SEO. Google wants to consume pages fast, too.</p>
<p>When a page is rendered into HTML on the server, all of the heavy-lifting is taken care of. For this reason, when the response makes it to the client’s browser, there isn’t much work left for the browser to display the page. It’s ready to go upon delivery.</p>
<h2 id="heading-drawbacks-of-ssr">Drawbacks of SSR</h2>
<p>There are plenty of reasons why most JavaScript frameworks have decided to include SSR as a rendering option in their frameworks. But there are a few drawbacks to SSR</p>
<p>Designers want pages to be interactive, and when a page is rendered into pure HTML for the client, it leaves a pretty bland user experience. So how do we make these pages interactive while preserving all the great benefits of server side rendering?</p>
<p>The answer is an added layer of complexity that goes by many names, but it’s most commonly known as code-splitting and hydration.</p>
<h3 id="heading-code-splitting-and-hydration">Code Splitting and Hydration</h3>
<p>In order for a page to be interactive, we need JavaScript to be sent to the client. SSR frameworks such as Next.js and Astro allow us to build an HTML only page on the server that can be sent to the client fast, while allowing for specific bundles of JavaScript to be sent to the client after the initial HTML has loaded.</p>
<p>In the React world, this process is known as hydration. The code is split into manageable chunks that can then be requested on an as needed basis and injected, or <em>hydrated,</em> into the client page to add interactivity and functionality.</p>
<p>You may be wondering why this is a “drawback.” Well, the idea itself isn’t the drawback, it’s the technical challenge that comes along with it. Isomorphic React and other technologies that are used to accomplish this goal are notoriously complex, and it takes intimate knowledge of a framework to program these sites efficiently.</p>
<h2 id="heading-benefits-of-csr">Benefits of CSR</h2>
<p>The benefits of client side rendering are essentially the polar opposite of server side rendering. We have excellent availability for interactive functionality, as the entire HTML page is built using JavaScript on the client. In fact, the entire CSR framework is often sent to the client in a purely client side rendering environment.</p>
<p>For this reason, once the page is initially loaded everything is very responsive for the end user. That’s because everything, including the code for all other pages, is loaded along with the initial page load.</p>
<p>From a developer’s standpoint, client side rendering is a great experience. The complexity of sharing the workload with the server is non-existent, and we can focus on building reusable interactive components that make for a streamlined development process.</p>
<h2 id="heading-drawbacks-of-csr">Drawbacks of CSR</h2>
<p>Soon after the explosion of CSR frameworks, SEO specialists started to realize that Google and other search engines don’t do a good job indexing these pages. The synopsis was clear: pure CSR sucks for SEO.</p>
<p>Initial page load speed is the main drawback here. When using CSR, the page is initially sent to the client as an empty HTML shell with no content. This empty husk is often what Google and other search engines see, which isn’t desirable for obvious reasons.</p>
<p>The JavaScript will build the page pretty quickly, but in practice most search engines still have trouble indexing the content after the DOM manipulation has completed and the HTML is rendered.</p>
<p>In the worst case scenario, the load time of a poorly built client side rendering app can even begin to negatively affect user experience, which is the ultimate blunder.</p>
<h2 id="heading-when-to-use-ssr-vs-csr">When to Use SSR vs CSR</h2>
<p>Based on what we’ve learned so far, it should be no surprise that server side rendering is a great choice when initial page load is a priority and technical SEO is important. But that’s not the only driving factor behind this consideration.</p>
<p>When a site has a ton of dynamic and frequently changing data, server side rendering allows developers to share the workload of retrieving content.</p>
<p>When using a purely client side rendering app for data intensive sites, it requires many calls from the client to the server to fetch the data. This can lead to pages becoming bogged down and slow to load, which can result in a poor user experience.</p>
<p>Server side rendering addresses this issue by allowing the server to pre-fetch and pre-render the necessary data before sending it to the client.</p>
<p>Remember, most server side rendering implementations aren’t <em>purely</em> SSR, they just get the heavy stuff out of the way. Developers still have the option to send specific, small bundles of JavaScript after the fact that add interactivity and even data fetching, in essence sharing the data fetching load with the server.</p>
<h2 id="heading-how-to-leverage-ssr-for-your-project">How to Leverage SSR for Your Project</h2>
<p>Unless you’re trying to build a framework of your own, SSR isn’t something you want to implement from scratch. Luckily, there are many frameworks and libraries that can help you leverage SSR in your project.</p>
<p>One popular option is <a href="https://www.freecodecamp.org/news/nextjs-seo/">Next.js for SEO</a>, a React framework that provides built-in support for SSR, along with code-splitting and other performance optimizations.</p>
<p>When it comes to leveraging server side rendering in a way that maximizes its performance benefits, you should be mindful of the impact of your application's data fetching distribution. Heavy data loads can slow down the SSR process and impact the performance of your application, which is one reason developers fetch data from the client as well.</p>
<p>When it comes to data fetching and processing on the server side, you can also start to incur some pretty hefty fees from your hosting provider. Keep a close eye on this if your project demands include an abundance of external data.</p>
<h2 id="heading-overview-and-concluding-thoughts">Overview and Concluding Thoughts</h2>
<p>Server-side rendering (SSR) can be a powerful tool for improving the performance and user experience of web applications. By rendering HTML on the server before sending it to the client, SSR can significantly reduce the time required to display a web page, resulting in faster load times and a better user experience.</p>
<p>When used correctly, the technical perks of SSR usually translate to better SEO as well, as it provides search engines with easily crawlable HTML documents. If you are interested in learning more about server side rendering, check out <a href="https://ohmycrawl.com/">OhMyCrawl</a> to learn more.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Next.js SEO for Developers – How to Build Highly Performant Apps with Next ]]>
                </title>
                <description>
                    <![CDATA[ Next.js is a popular React-based web framework that has gained popularity and a growing community in recent years. It's a powerful tool for building fast and SEO-friendly web applications with dynamic ]]>
                </description>
                <link>https://www.freecodecamp.org/news/nextjs-seo/</link>
                <guid isPermaLink="false">66d460f4c7632f8bfbf1e4b7</guid>
                
                    <category>
                        <![CDATA[ Next.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ performance ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SEO ]]>
                    </category>
                
                    <category>
                        <![CDATA[ web performance ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Scott M ]]>
                </dc:creator>
                <pubDate>Mon, 20 Mar 2023 21:17:55 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/03/pexels-andrei-photo-2127783.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Next.js is a popular React-based web framework that has gained popularity and a growing community in recent years. It's a powerful tool for building fast and SEO-friendly web applications with dynamic pages that work great on mobile devices.</p>
<p>Due to the complex nature of isomorphic system design, Next.js SEO can be a tricky topic to get your head around. Especially if you're coming from traditional React apps and you're relying solely on documentation.</p>
<p>With its built-in support for server-side rendering, static site generation, and now React server components, Next.js provides a robust platform for achieving quality SEO web metrics in your web application. It also helps you deliver exceptional user experiences across multiple pages in Node and React apps while making them SEO friendly.</p>
<h2 id="heading-why-should-you-learn-nextjs-for-front-end-development">Why Should You Learn NextJS for Front End Development?</h2>
<p>In short, the newest version of NextJS is an open source platform that addresses a lot of rendering issues that React currently has. I wrote this article because a lot of front end developers get mad at me :-D.</p>
<p>They spend 6-9 months developing a React App, and then I have to ask them to refactor their code.</p>
<p>Next.js avoids a lot of rending issues – it makes it very easy for search engines to understand what your website is all about.</p>
<h3 id="heading-who-will-get-the-most-out-of-this-article">Who Will get the most out of this article?</h3>
<p>This will be very helpful to you if you're a marketer or more advanced developer who's experiencing SEO issues.</p>
<p>However newer developers are welcome to review this info as well, as it will help you in the long term.</p>
<h2 id="heading-how-should-you-render-your-next-js-web-page-application">How Should You Render Your Next JS Web Page Application?</h2>
<p>I've personally reviewed a ton of theses websites from my consultancy <a href="https://www.ohmycrawl.com/">OhMyCrawl</a> and made a video overview to help understand the benefits of using frameworks such as Next.js for SEO:</p>
<div class="embed-wrapper"><iframe width="560" height="315" src="https://www.youtube.com/embed/U8V0rk5AwBU" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>

<h2 id="heading-how-is-next-seo-different-from-other-frameworks">How is Next SEO Different from Other Frameworks?</h2>
<p>Next SEO sets itself apart by streamlining so many features and free tools into a well-organized package that you can easily digest and apply in your single page applications. Next does a great job when it comes to tasks such as search engine optimization, image optimization, and minimizing cumulative layout shift.</p>
<p>The benefits of Next.js SEO don't stop there. We’ll be covering many of the goodies that Next.js brings to the table related to search engines, old and new.</p>
<h2 id="heading-search-engines-ssr-and-ssg-concepts-are-evolving">Search Engines, SSR, and SSG Concepts Are Evolving</h2>
<p>Most developers and SEO experts have become pretty comfortable with the existing page creation strategies and the whole SSR vs SSG paradigm. They've also developed a high level of trust in version 12 of Next.js, which provides a clear cut way to handle these two forms of page generation.</p>
<p>As usual, though, yet another web app paradigm shift is underway, this time in the form of React Server Components (RSCs), which are included by default in Next.js version 13.</p>
<h3 id="heading-seo-concepts-havent-changed-just-the-approach">SEO Concepts Haven’t Changed – Just the Approach</h3>
<p>Next JS SEO won’t change much conceptually. If you’re looking for good search engine results and organic traffic, the game still revolves around the notion of fast page loads, quick paints, low cumulative layout shifts, and all the rest. Static pages still play a large role as well.</p>
<p>But Next.js gives us some pretty cool and novel features that help facilitate excellent search engine metrics, and it’s more than just React Server Components.</p>
<p>We'll explore some best practices along with a few different techniques and strategies for achieving great SEO optimization web metrics with Next.js. We'll also see how to take advantage of its unique features to improve your website's search engine visibility and user engagement.</p>
<h2 id="heading-whats-new-with-nextjs-13-that-relates-to-seo">What’s New With Next.js 13 that Relates to SEO?</h2>
<p>Rather than give you a comprehensive guide to the technical changes found in version 13, we’re going to focus mainly on Next JS SEO related advantages. We'll also look at how you can leverage the best SEO practices to achieve the best possible results in search engines with much less sweat off your back than is typically needed.</p>
<p>The version 13 changes we’ll discuss here are as follows:</p>
<ul>
<li><p>React server components</p>
</li>
<li><p>Streaming UI chunks</p>
</li>
<li><p>Updated Next Image component</p>
</li>
<li><p>Next Font component</p>
</li>
</ul>
<p>On top of the existing default SEO properties of Next, these particular upgrades are the cornerstone of Next.js SEO improvements in version 13. Each one is awesome for its own reasons, which we’ll be going over shortly.</p>
<h3 id="heading-react-server-components">React Server Components</h3>
<p>RSCs allow for a more fine-grained approach to rendering on both the client and the server.</p>
<p>Rather than being forced to decide whether to render an entire page on the client or server upon user requests, React allows developers to choose whether components should be rendered on the server or the client. This can give you a huge advantage in search engine results pages.</p>
<p>A huge majority of page optimization these days revolves around sending less JavaScript to the client. After all, this is the primary benefit of using pre-rendering and Server Side Rendering to create web pages and HTML pages.</p>
<p>RSCs are another tool to help achieve this end and gain as much SEO value from your web pages or single page applications as you can. This helps achieve better SEO by refreshing dynamic data in a React component while leaving the static parts of the page’s content intact.</p>
<h3 id="heading-streaming-ui-chunks">Streaming UI Chunks</h3>
<p>Next.js SEO made a huge leap adding RSC to the mix, and streaming UI chunks is the cherry on top. Streaming UI is a similar spin-off of a new and growing design pattern called “the island architecture,” which strives to send as little code to the client as possible at first load.</p>
<p>Allowing fine-grained control is great, but why not send a JavaScript-free, fully rendered page to the client, and send the rest later? That’s exactly what streaming UI chunks accomplish.</p>
<p>When Next.js renders a page on the server, the page typically comes with all the JavaScript bundled up and sent along with it. The ability to stream chunks of data eliminates this need, and allows an extremely tiny static page to be sent to the client, significantly improving web metrics such as first contentful paint and overall page speed.</p>
<h3 id="heading-nextjs-13-app-directory">Next.js 13 App Directory</h3>
<p>When you start a new Next.js 13 project, you’ll notice a new directory called <strong>app</strong>. Everything within the app directory is preconfigured to allow for RSCs and streaming UI chunks. You need only create a <a href="https://beta.nextjs.org/docs/routing/loading-ui">loading.js</a> component, which will wrap the page component entirely and any children within a suspense boundary.</p>
<p>You can achieve an <em>even more</em> granular loading pattern by manually creating the suspense boundaries yourself, essentially allowing for unlimited control over what gets loaded upon the initial request.</p>
<p>The steps for streaming UI chunks go something like this:</p>
<ol>
<li><p>User makes initial request.</p>
</li>
<li><p>Barebones HTML page is rendered and sent to the client.</p>
</li>
<li><p>JavaScript bundles are being prepared on the server.</p>
</li>
<li><p>A page section requiring JavaScript becomes visible in the client browser.</p>
</li>
<li><p>JavaScript bundle for only that component is sent to the client.</p>
</li>
</ol>
<p>This new tooling has important implications for technical SEO by allowing more interactive pages to compete with static pages in regards to page load speed and other web metrics that are used as ranking factors in search results by search engines.</p>
<h3 id="heading-updated-next-image-component">Updated Next Image Component</h3>
<p>Another important upgrade to the Next.js SEO sphere is the Image component. Although it’s been somewhat understated, the biggest improvement in my opinion is the utilization of native lazy loading.</p>
<p>Browsers have had great support for native lazy loading for some time now, and including extra JavaScript for this feature is simply a waste of bandwidth.</p>
<p>A few other great improvement for SEO are:</p>
<ul>
<li><p>Required alt tag by default.</p>
</li>
<li><p>Better validation to pinpoint errors involving invalid properties.</p>
</li>
<li><p>More easily styled due to a more HTML-like interface.</p>
</li>
</ul>
<p>Overall, the new Image component is simplified and slimmed down, and in the programming world simpler is almost always better.</p>
<h3 id="heading-the-next-font-component">The Next Font Component</h3>
<p>The font component is a huge win for Next.js SEO, and it will certainly help alleviate many headaches in the future. Any experienced developer knows how tedious it can be configuring fonts properly (proper is not relative in this case!).</p>
<p>Cumulative layout shifts due to slow loading is a common nuisance, and search engines like Google have <a href="https://developers.google.com/publisher-tag/guides/minimize-layout-shift">openly stated</a> that CLS is an important web metric.</p>
<p>Depending on the framework you’re working with (Gatsby comes to mind), it can be tricky getting your fonts to preload effectively. Making external requests to font repositories such as Google have been a necessary evil for some time, creating a hard to manage bottleneck in many SPA applications.</p>
<p>The Next Font Component aims to solve this problem by fetching all external fonts at build time, and self-hosting them from your own domain. Fonts are also optimized automatically, and zero cumulative layout shift is accomplished by automatic utilization of the CSS <strong>size-adjust</strong> property.</p>
<h2 id="heading-common-seo-related-tasks-with-nextjs">Common SEO-Related Tasks with Next.js</h2>
<p>There are a few important topics to consider when configuring common Next.js SEO tasks for version 13.</p>
<h3 id="heading-nextjs-seo-with-version-13">Next.js SEO With Version 13</h3>
<p>The Next version of the React Head component has typically been used to assign values to meta tags within the document head and also to inject structured data.</p>
<p>With version 13, however, the Head component goes out the window. At first, Next opted to utilize a special file called <strong>head.js</strong> that works in a similar fashion as the Head component. After version 13.2, Next implemented the <strong>Metadata</strong> component, which is a more proprietary implementation to solving the metadata problem by easily populating meta tags.</p>
<p>Let’s take a closer look at these two common SEO tasks, and examine how they used to be handled as opposed to the new version 13 way.</p>
<h2 id="heading-how-to-configure-the-head-tag-for-search-engine-optimization">How to Configure the Head Tag for Search Engine Optimization</h2>
<p>Prior to version 13, we would import the <strong>Next/Head</strong> component, and set any necessary metadata values such as title and description or other meta tags within the html file of the web page.</p>
<p>A simple example of the Head component in version 12 looks like this:</p>
<pre><code class="language-js">import Head from 'next/head'
const structData = {
'@context': 'https://schema.org',
'@type': 'BlogPosting',
headline: 'Learning Next.js SEO',
description: 'All about Next.js features and more',
author: [
{
'@type': 'Person',
name: 'Jane Doe',
},
],
datePublished: '2023-02-16T09:00:00.000Z',
};
function IndexPage() {
return (
&lt;div&gt;
&lt;Head&gt;
&lt;meta name="viewport" content="initial-scale=1.0, width=device-width" /&gt;
&lt;title&gt;My page title&lt;/title&gt;
&lt;script
key="structured-1"
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(structData) }}
/&gt;
&lt;/Head&gt;
&lt;p&gt;Hello world!&lt;/p&gt;
&lt;/div&gt;
)
}
export default IndexPage
</code></pre>
<p>Adding structured data such as title and description or any additional meta tags in a page’s metadata is a simple matter of including a script tag with the <strong>dangerouslySetInnerHTML</strong> attribute, as seen in the example.</p>
<p>Most developers code an SEO component that utilizes the Head component in order to achieve a more DRY (don’t repeat yourself) approach. Here, you prevent the same data or HTML files from being sent multiple times to the user. But under the hood it’s all the same, and Head was the go-to approach for optimizing a web page in regards to meta tags.</p>
<h3 id="heading-the-next-special-headjs-file">The Next Special head.js File</h3>
<p>With version 13, you can forget all about the usual Head component. Starting with the first iteration of version 13, Next implemented the <strong>head.js (or .tsx)</strong> file. This file can be included within any folder inside the app directory to dynamically manage SEO metadata and declare which tags, along with their values, will be utilized for a particular route and particular page.</p>
<p>Every folder in the app directory accounts for a new route, which is why you’ll need to create a <strong>head.js</strong> file within each folder to configure your metadata values. Here’s an example <strong>head.js</strong> file:</p>
<pre><code class="language-js">export default function Head(params) {
return (
&lt;&gt;
&lt;title&gt;head.js Example&lt;/title&gt;
&lt;/&gt;
);
}
</code></pre>
<p>Notice that we return a React fragment rather than an actual head tag, or any other element. This is a required aspect of the <strong>head.js</strong> component.</p>
<p>You can only return the following metadata tags from within the fragment:</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use React Helmet – With Example Use Case ]]>
                </title>
                <description>
                    <![CDATA[ Because of the nature of single page applications (SPAs), modifying metadata in React apps can be tricky without using a helper library. Lucky for us, that library already exists – and it's called Rea ]]>
                </description>
                <link>https://www.freecodecamp.org/news/react-helmet-examples/</link>
                <guid isPermaLink="false">66d460f737bd2215d1e245cf</guid>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Scott M ]]>
                </dc:creator>
                <pubDate>Wed, 05 Oct 2022 16:36:10 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/10/react-head-examples.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Because of the nature of single page applications (SPAs), modifying metadata in React apps can be tricky without using a helper library. Lucky for us, that library already exists –&nbsp;and it's called React Helmet.</p>
<p>Leveraging Helmet for metadata inclusion can significantly simplify the process of making a React app SEO and social media friendly.</p>
<p>Helmet lets us insert metadata into the tag in much the same way we would using standard HTML syntax.</p>
<p>In this article, we'll cover the following steps:</p>
<ol>
<li><p>How to install and import the React Helmet library.</p>
</li>
<li><p>Basic usage for client and server side rendering (CSR vs SSR).</p>
</li>
<li><p>More advanced usage of Helmet for setting up an SEO component.</p>
</li>
</ol>
<p>In order to understand these topics, you should have a basic knowledge of the React library.</p>
<h2 id="heading-react-helmet-installation-and-setup">React Helmet Installation and Setup</h2>
<p>If you're already familiar with using React and Node, installing Helmet should be a breeze.</p>
<p>However, before demonstrating, it's important to note that the standard <strong>react-helmet</strong> library is now considered deprecated. Instead, you should use <strong>react-helmet-async</strong>.</p>
<p>This is because react-helmet led to a few bugs that resulted in memory leaks and poor data integrity. Suffice it to say, when React developers mention Helmet, they're almost always referring to <strong>react-helmet-async</strong>.</p>
<p>Now to the installation. Simply navigate to your project's directory in the terminal, and install react-helmet-async with your package manager of choice. Here's the syntax for yarn and npm:</p>
<pre><code class="language-plaintext">yarn add react-helmet-async
npm i react-helmet-async
</code></pre>
<p>Once the installation completes, you can move on to importing and utilizing the Helmet component library.</p>
<h2 id="heading-react-helmet-basic-concepts-and-usage">React Helmet Basic Concepts and Usage</h2>
<p>The two components we'll be importing from <strong>react-helmet-async</strong> are called <strong>Helmet</strong> and <strong>HelmetProvider</strong>.</p>
<ol>
<li><p><strong>HelmetProvider</strong> will wrap the entire app component in order to create context and prevent memory leaks. Therefore, this component will only need to be imported in the root <strong>App</strong> component.</p>
</li>
<li><p><strong>Helmet</strong> will be imported into any page component where you want to implement meta tags. Think of as the tag for the page in question.</p>
</li>
</ol>
<p>We're going to start with basic usage of both client side rendering (CSR) and server side rendering (SSR). Let's start by seeing how things work in a basic CSR implementation:</p>
<pre><code class="language-javascript">import React from 'react';
import { HelmetProvider } from 'react-helmet-async';
import NavBar from './NavBar';
import Landing from `./Landing;
export default function App() {
return (
&lt;HelmetProvider&gt;
&lt;NavBar /&gt;
&lt;Landing /&gt;
&lt;/HelmetProvider&gt;
)}
</code></pre>
<p>As you can see, in the <strong>App</strong> component we only imported the <code>HelmetProvider</code> component from <strong>react-helmet-async</strong>. Pretty simple.</p>
<p>The SSR implementation is very similar, with one small addition. Let's have a look and see if you can spot the difference:</p>
<pre><code class="language-javascript">import React from 'react';
import { HelmetProvider } from 'react-helmet-async';
import NavBar from './NavBar';
import Landing from `./Landing;
export default function App() {
const helmetContext = {};
return (
&lt;HelmetProvider context={helmetContext}&gt;
&lt;NavBar /&gt;
&lt;Landing /&gt;
&lt;/HelmetProvider&gt;
)}
</code></pre>
<p>If you noticed the addition of the <strong>helmetContext</strong> variable being passed as a prop to our <strong>HelmetProvider</strong>, you nailed it!</p>
<p>This paradigm is found using most popular state management systems such as Redux, and helps ensure that context is never scoped outside of the current instance of your app.</p>
<p>Now, let's assume the following page component is the landing page for your React app:</p>
<pre><code class="language-javascript">import React from 'react';
import { Helmet } from 'react-helmet-async';
export default function Landing() {
return (
&lt;div&gt;
&lt;Helmet&gt;
&lt;title&gt;Learning React Helmet!&lt;/title&gt;
&lt;meta name='description' content='Beginner friendly page for learning React Helmet.' /&gt;
&lt;/Helmet&gt;
&lt;h1&gt;Cool Landing Page!&lt;/h1&gt;
&lt;/div&gt;
)
}
</code></pre>
<p>A quick review of the Landing page component shows that we imported the <strong>Helmet</strong> component, and used it to add the <em>title</em> and <em>description</em> metadata to the page.</p>
<p>We simply add the HTML equivalent meta tag inside the Helmet component, and the work of adding this to the HTML tag is handled for us.</p>
<p>Awesome! We're now on the road to creating an SEO-friendly React app.</p>
<h2 id="heading-creating-an-seo-component-with-react-helmet">Creating an SEO Component With React Helmet</h2>
<p>Metadata isn't only about Google search results. We also want social media posts that reference our site to show up as cool preview cards.</p>
<p>When it comes to metadata and meta tags, there's a ton of different variants to remember. Facebook uses <strong>og</strong> (open graph) tags, Twitter uses its own <strong>twitter</strong> variant, and so on.</p>
<h2 id="heading-how-to-use-components-for-abstraction">How to Use Components for Abstraction</h2>
<p>One cool thing about creating React components with props is that you can reuse a prop inside the component however you please.</p>
<p>Using this knowledge, you can create a component called SEO that abstracts away the usage for commonly used metadata tags, saving you from having to track down each tag variant every time you build an SEO-friendly app.</p>
<p>An example SEO component that streamlines the process of adding Facebook and Twitter tags could look like this:</p>
<pre><code class="language-javascript">import React from 'react';
import { Helmet } from 'react-helmet-async';
export default function SEO({title, description, name, type}) {
return (
&lt;Helmet&gt;
{ /* Standard metadata tags */ }
&lt;title&gt;{title}&lt;/title&gt;
&lt;meta name='description' content={description} /&gt;
{ /* End standard metadata tags */ }
{ /* Facebook tags */ }
&lt;meta property="og:type" content={type} /&gt;
&lt;meta property="og:title" content={title} /&gt;
&lt;meta property="og:description" content={description} /&gt;
{ /* End Facebook tags */ }
{ /* Twitter tags */ }
&lt;meta name="twitter:creator" content={name} /&gt;}
&lt;meta name="twitter:card" content={type} /&gt;
&lt;meta name="twitter:title" content={title} /&gt;
&lt;meta name="twitter:description" content={description} /&gt;
{ /* End Twitter tags */ }
&lt;/Helmet&gt;
)
}
</code></pre>
<p>As shown above, our component accepts four props: title, description, name, and type. Using these four props, we were able to distribute the values across nine different types of meta tags!</p>
<p>Here’s an example of how we could implement this component in our <strong>Landing</strong> page component:</p>
<pre><code class="language-javascript">import React from 'react';
import { SEO } from './SEO’;
export default function Landing() {
return (
&lt;div&gt;
&lt;SEO
title=’Learning React Helmet!’
description=’Beginner friendly page for learning React Helmet.'
name=’Company name.’
type=’article’ /&gt;
&lt;h1&gt;Cool Landing Page!&lt;/h1&gt;
&lt;/div&gt;
)
}
</code></pre>
<p>So, all we had to do is pass in our four props, and our custom SEO component handles all the heavy lifting of creating the multiple different types of metadata tags. Nice.</p>
<p>This example is far from an exhaustive list of meta tags. It doesn't take much imagination to visualize how useful this component would be if you wanted to include all relevant meta tags for your site.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article we went over why React Helmet is a useful addition to your React app. You learned not only basic setup and usage, but also a more advanced implementation that helps abstract away much of the repetitive work involved in metadata tags.</p>
<p>Hopefully you now feel confident enough to enhance your <a href="https://www.ohmycrawl.com/react-seo/">React SEO</a> and social media performance by implementing the React Helmet Async library. Good luck and happy coding!</p>
<p>For more information on how to set up your JavaScript websites for search engine success, check out <a href="http://ohmycrawl.com/">ohmycrawl.com</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Configure Metadata for a Single-Page Application ]]>
                </title>
                <description>
                    <![CDATA[ Why Metadata Matters Metadata is an integral part of any modern web app, because it's inherently tethered to search engine optimization (SEO). Search engines and their respective results page (SERPS)  ]]>
                </description>
                <link>https://www.freecodecamp.org/news/configure-metadata-in-single-page-applications/</link>
                <guid isPermaLink="false">66d460f0bd438296f45cd3b6</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ metadata ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SEO ]]>
                    </category>
                
                    <category>
                        <![CDATA[  Single Page Applications  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Scott M ]]>
                </dc:creator>
                <pubDate>Tue, 20 Sep 2022 17:20:15 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/09/meta-data-for-spa-seo.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <h2 id="heading-why-metadata-matters">Why Metadata Matters</h2>
<p>Metadata is an integral part of any modern web app, because it's inherently tethered to search engine optimization (SEO).</p>
<p>Search engines and their respective results page (SERPS) rely on metadata to properly index and display relative information for each site.</p>
<p>Also, meta tags are relied upon to properly display content from your site on a given social media platform, such as articles or items for sale.</p>
<p>For this reason, it's crucial to understand how metadata is configured in a modern web app.</p>
<p>The single page application (SPA) is a modern web app implementation that is incredibly popular. Most frameworks today utilize it in some way. Configuring metadata in today’s most popular SPA frameworks will be the focus of this tutorial.</p>
<h2 id="heading-the-single-page-application-and-metadata">The Single Page Application and Metadata</h2>
<p>The nature of SPAs make configuring metadata a less straightforward process than classic multiple page applications. I'm going to try to clarify this topic by describing the following key concepts:</p>
<ol>
<li><p>The structure of an SPA.</p>
</li>
<li><p>The problem with modifying metadata in an SPA.</p>
</li>
<li><p>Available metadata solutions using what are probably the three most popular SPA frameworks: React, Svelte, and Vue.</p>
</li>
</ol>
<p>You should have a basic understanding of HTML, metadata, and one of the three SPA frameworks to understand the concepts we’ll be going over. But, I’ll be keeping things beginner friendly, so don’t worry!</p>
<h2 id="heading-how-single-page-applications-work">How Single Page Applications Work</h2>
<p>Before diving in, you need a firm grasp of what constitutes an SPA.</p>
<p>As the name implies, a single page application literally consists of a single HTML page sent down from the server. This page is just an empty HTML shell, and will look something like this:</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
	&lt;html&gt;
		&lt;head&gt;
		&lt;title&gt;Home | Demystifying SPA Metadata&lt;/title&gt;
		&lt;meta name="description" content="How to configure popular SPA 			frameworks to maintain quality site metadata."/&gt;
		&lt;link rel="stylesheet" href="./stylesheet.css" type="text/css" 			/&gt;
		&lt;/head&gt;
		&lt;body&gt;
			&lt;script src="/bundle.min.js" type="text/javascript"&gt;					&lt;/script&gt;
		&lt;/body&gt;
	&lt;/html&gt;
</code></pre>
<p>You might be wondering how an entire website is derived from this empty HTML shell.</p>
<p>This is possible because along with the HTML page will be extensive client-side JavaScript code that generates the content for each page. This code is included in the page via the</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
