<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anna Q. Harder</title>
    <description>The latest articles on DEV Community by Anna Q. Harder (@annaqharder).</description>
    <link>https://dev.to/annaqharder</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F970989%2F93282f96-d1a0-45de-8b2b-38351f17436a.jpeg</url>
      <title>DEV Community: Anna Q. Harder</title>
      <link>https://dev.to/annaqharder</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/annaqharder"/>
    <language>en</language>
    <item>
      <title>Hide/Show Password in React</title>
      <dc:creator>Anna Q. Harder</dc:creator>
      <pubDate>Thu, 16 Feb 2023 23:02:23 +0000</pubDate>
      <link>https://dev.to/annaqharder/hideshow-password-in-react-513a</link>
      <guid>https://dev.to/annaqharder/hideshow-password-in-react-513a</guid>
      <description>&lt;p&gt;When logging in or creating an account for a website or application, it is useful for a user to be able to see their password, especially when passwords are long and include different symbols. I implemented this show/hide password functionality in my React frontend capstone project at Flatiron School. There are many variations of this functionality such as a toggle button or icon change. I chose to use an eye and strikethrough eye icon for my website. &lt;/p&gt;

&lt;p&gt;First, I installed the React Icons Kit library and imported the library and the two icons into my React component: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import {Icon} from 'react-icons-kit';
import {eyeOff} from 'react-icons-kit/feather/eyeOff';
import {eye} from 'react-icons-kit/feather/eye'


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, I created three states. The first state was to manage and eventually set the password of a user, with an initial state of an empty string. The second state was for the type, which had an initial state of 'password'. This will be used in the controlled form to render the password on the page. The last state was for the icon, which had an initial state set as "eyeOff" icon because we want a user's password to be initially hidden: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const [password, setPassword] = useState("");
const [type, setType] = useState('password');
const [icon, setIcon] = useState(eyeOff);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I then created a function that would handle the toggle between the hide password (eyeOff icon) and the show password (eye icon): &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const handleToggle = () =&amp;gt; {
   if (type==='password'){
      setIcon(eye);
      setType('text')
   } else {
      setIcon(eyeOff)
      setType('password')
   }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This handleToggle function is saying: when the type is equal to 'password', have the icon set as eye open icon and show the password in text form, and when the type is anything else, have the icon set as the eyeOff icon and hid the password. &lt;/p&gt;

&lt;p&gt;Now that the logic is made, we want to render the password and the toggle hid/show functionality on the page. Inside the return: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

return (
     &amp;lt;div&amp;gt;
        &amp;lt;div&amp;gt;
           &amp;lt;div class="mb-4 flex"&amp;gt;
              &amp;lt;input
                  type={type}
                  name="password"
                  placeholder="Password"
                  value={password}
                  onChange={(e) =&amp;gt; setPassword(e.target.value)}
                  autoComplete="current-password"
             /&amp;gt;
             &amp;lt;span class="flex justify-around items-center" onClick={handleToggle}&amp;gt;
                  &amp;lt;Icon class="absolute mr-10" icon={icon} size={25}/&amp;gt;
              &amp;lt;/span&amp;gt;
            &amp;lt;/div&amp;gt;
         &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
); 


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I used Tailwind CSS framework to style the position of the icon so that the icon is within the password input. &lt;/p&gt;

&lt;p&gt;This is how the form looks with the eyeOff icon with password hidden: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fng8xazylr1cca55eikrz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fng8xazylr1cca55eikrz.png" alt="password hidden" width="800" height="619"&gt;&lt;/a&gt;&lt;br&gt;
And this is how the form looks with the eye icon with the password shown: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzueh17uon0gsiktg2i6n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzueh17uon0gsiktg2i6n.png" alt="password shown" width="800" height="581"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that's it! I originally though this functionality would be very difficult but I was pleasantly surprised how easy this feature was to implement. I hope this was a helpful tutorial! &lt;/p&gt;

</description>
      <category>react</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to Make Star Rating in React</title>
      <dc:creator>Anna Q. Harder</dc:creator>
      <pubDate>Thu, 16 Feb 2023 22:59:54 +0000</pubDate>
      <link>https://dev.to/annaqharder/how-to-make-star-rating-in-react-2e6f</link>
      <guid>https://dev.to/annaqharder/how-to-make-star-rating-in-react-2e6f</guid>
      <description>&lt;p&gt;For my capstone project at Flatiron School, I created an application in which users can track and manage the eateries (ex: restaurants, cafes/bakeries/coffee shops, &amp;amp; bars/breweries) they have visited and the food and drink they ordered so visits can be referenced at a later time. &lt;/p&gt;

&lt;p&gt;One of the features I wanted to include was a rating functionality. Instead of displaying just numerical ratings, I wanted to display those ratings via star icons. In addition to displaying those numerical ratings into stars, I wanted users to be able to click on the stars to create or edit their rating for an eatery.&lt;/p&gt;

&lt;p&gt;I used a React frontend to accomplish this task. I will first describe how to display ratings via stars, and then describe how to dynamically change the star ratings when creating or editing a rating. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to Convert Numerical Rating into Star Rating
&lt;/h2&gt;

&lt;p&gt;Inside the component that holds and displays the eatery rating, I first declared a constant that holds the colors of the stars when they are empty and filled (this can alternatively be done via inline styling). &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const colors = {
        orange: "#F2C265",
        grey: "a9a9a9"
    }


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;One of my attributes of an Eatery is the "rating" declared as an integer on the backend. This numerical, integer rating was then translated into stars in React. To create the stars, I first installed the React Icons Kit library and selected the FaStar icon, and imported it into my component. I then created an array of 5 stars, called "stars", where the .fill was 0. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const stars = Array(5).fill(0)


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Now, in my return, this is where the star rating is displayed on the page. I mapped over the star array and returned the star icon where the color of the star is filled based on the rating of the specific eatery. For example, if a user gave the eatery 4 stars, 4/5 stars would be filled in with the color = orange, and 1/5 stars would remain the color = grey. (I also chose to display the numerical star rating next to the star icons.)&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

return (
  &amp;lt;div&amp;gt;
     {stars.map((_, index) =&amp;gt; {
        return (
             &amp;lt;FaStar
                 key={index}
                 size={24}
                 color={(rating) &amp;gt; index ? colors.orange : colors.grey}
              /&amp;gt;
      &amp;lt;p&amp;gt;({rating} Stars)&amp;lt;/p&amp;gt;
         )
      })}
   &amp;lt;/div&amp;gt;
);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffi8g7vmahw5n5h3kifu3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffi8g7vmahw5n5h3kifu3.png" alt="Example"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to Dynamically Create and Edit Star Icon Rating
&lt;/h2&gt;

&lt;p&gt;Display a static rating via star icons is more simplistic than creating dynamically changing star icons. Dynamically creating or editing star icon ratings requires useState and event listeners. The same React icon was imported and the same color constant and star array described above were also created. &lt;/p&gt;

&lt;p&gt;First, inside the component where I want to create (or edit) a star icon rating, I created two states. One for the rating attribute, with the initial state set as the current rating (if the user was editing the rating). The other state was created for selecting the stars when rating called "hoverValue". Initial state for the rating attribute was set as the current rating (if the user was editing the rating). Initial state was declared as undefined because we don't want to give the hoverValue a pre-determined state - we want it to be 0 before we start rating. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const [rating, setRating] = useState(eatery.rating)
const [hoverValue, setHoverValue] = useState(undefined)


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;When rating, I wanted to hover over the stars and have them be filled with the orange color before settling on the final rating. To do this, I added a some event listeners to handle this functionality: &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const handleMouseOverStar = value =&amp;gt; {
    setHoverValue(value)
};

const handleMouseLeaveStar = () =&amp;gt; {
    setHoverValue(undefined)
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;The handleMouseOver takes in a value when the user hovers over the star icons and sets that value in the setHoverValue setter function. The handleMouseLeaveStar removes the stars when an user moves away from the stars (i.e. wants to reduce the amount of stars they have chosen). &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const handleClickStar = value =&amp;gt; {
    setRating(value)
};


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;The handleClickStar takes the value of the rating a user choses via a mouse click and sets that value to the setRating setter function. This means, the number of stars a user selects will be the rating of the eatery. &lt;/p&gt;

&lt;p&gt;Now, we need to actually display this functionality on the page. In the return, we are going to map over the stars array (like before) and now include the event listeners. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

return (
  &amp;lt;div&amp;gt;
     {stars.map((_, index) =&amp;gt; {
          return (
               &amp;lt;FaStar
                   key={index}
                   size={24}
                   value={rating}
                   onChange={(e) =&amp;gt; setRating(e.target.value)}
                   color={(hoverValue || rating) &amp;gt; index ? colors.orange : colors.grey}
                   onClick={() =&amp;gt; handleClickStar(index + 1)}
                   onMouseOver={() =&amp;gt; handleMouseOverStar(index + 1)}
                   onMouseLeave={() =&amp;gt; handleMouseLeaveStar}
                /&amp;gt;
           )
       })}
  &amp;lt;/div&amp;gt;
);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;The onChange event listener manages the setting of the rating, the onClick event listener manages the incrementation of the star icon rating, and the onMouseOver and onMouseLeave manage the hover effects of the star rating.   &lt;/p&gt;

&lt;p&gt;It is difficult to show the functionality of this hover star rating via images, but if you are curious how this works, you can play around with it on my website: &lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://leftovers-2mnc.onrender.com/" rel="noopener noreferrer"&gt;
      leftovers-2mnc.onrender.com
    &lt;/a&gt;
&lt;/div&gt;



&lt;p&gt;I think this functionality is a fun feature to add to any website that includes rating, and I hope this tutorial was helpful! &lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>useHistory Hook in React for App Navigation</title>
      <dc:creator>Anna Q. Harder</dc:creator>
      <pubDate>Mon, 09 Jan 2023 18:52:07 +0000</pubDate>
      <link>https://dev.to/annaqharder/usehistory-hook-in-react-for-app-navigation-2ol4</link>
      <guid>https://dev.to/annaqharder/usehistory-hook-in-react-for-app-navigation-2ol4</guid>
      <description>&lt;p&gt;In my most recent project, my partner and I built a (faux) art auction site, Rotheby's. One of the features we wanted to implement was the ability of a user to click on the "Place Bid" button a specific piece of artwork, and for the user to be re-routed/directed to a new page displaying that individual piece of artwork and a form to place a bid. To implement this functionality, we called upon React's useHistory hook, and more specifically, the .push() method.&lt;/p&gt;

&lt;p&gt;Auction Homepage with all artworks:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq452dah1nryv9a9hxrmt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq452dah1nryv9a9hxrmt.png" alt="Artworks Homepage" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Re-directed page with individual artwork:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fipg4q9yzoqxraf4b40ny.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fipg4q9yzoqxraf4b40ny.png" alt="Individual Artwork" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Background on React's History Object &amp;amp; useHistory Hook
&lt;/h2&gt;

&lt;p&gt;The history package is a major dependency of ReactRouter that provides various implementations for managing session history. The useHistory hook accesses the ReactRouter history object and allows navigation to other routes using specific methods, such as .push() and .replace().&lt;/p&gt;

&lt;p&gt;With the useHistory hook, a user can efficiently and seamlessly navigate to a specific URL, and move forward and back on different pages within an app. For my partner and my art auction application, we used the .push() method, which adds a new entry to the history stack. This provided us a way to programmatically control the browser's history and change the URL displayed in the address bar without reloading the page. &lt;/p&gt;
&lt;h2&gt;
  
  
  Implementation of useHistory and .push()
&lt;/h2&gt;

&lt;p&gt;In the Artwork component (in our React app): &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;we imported the useHistory hook at the top of the component, which gave us access to the useHistory functionality &lt;/li&gt;
&lt;li&gt;we declared the "history" variable to the useHistory hook&lt;/li&gt;
&lt;li&gt;we defined the handleRedirect function which includes the history variable, the .push() method, and the route we want to navigate to. For this project we wanted to re-direct the user to the specific artwork page (each artwork in our database had an id value associated with it)&lt;/li&gt;
&lt;li&gt;we assigned the handleRedirect function to the onClick event handler on the "Place Bid" button
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {useHistory } from "react-router-dom";

 const history = useHistory();

 function handleRedirect() {
   // redirect to /artworks/:id
   history.push(`/artworks/${id}`);
 }

return(
     &amp;lt;button className="bidButton" onClick={handleRedirect}&amp;gt;
            Place Bid
     &amp;lt;/button&amp;gt;
); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once the user clicks on the "Place Bid" button, they are re-directed to the URL with that specific artwork's id and the new page with the artwork's details and the form to bid on that piece of artwork. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;** Note:&lt;/em&gt; the route (/artworks/:id) is associated with a route declared in a higher-level component (App.js) which routes to the ArtworkDetails component containing the code for the artwork's details and bidding form. &lt;/p&gt;

&lt;p&gt;All Artwork URL: &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2r2jogji84b1b4r953rm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2r2jogji84b1b4r953rm.png" alt="All Artwork URL" width="456" height="66"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Individual Artwork URL (the artwork selected has id=1): &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhwk3g6qwjmrzmtichzy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhwk3g6qwjmrzmtichzy.png" alt="Individual Artwork URL" width="512" height="78"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Wrap Up
&lt;/h2&gt;

&lt;p&gt;Learning about the useHistory hook and .push() methods were vital for my partner and I to successfully build the auction site we had imagined. I hope this blog post was helpful in providing a quick breakdown of the topic and associated example! &lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

&lt;p&gt;My partner for this project was:&lt;/p&gt;


&lt;div class="ltag__user ltag__user__id__973741"&gt;
    &lt;a href="/racheljoyh" class="ltag__user__link profile-image-link"&gt;
      &lt;div class="ltag__user__pic"&gt;
        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F973741%2Fb13e0598-46ec-4f6e-aea9-2604e196d737.jpg" alt="racheljoyh image"&gt;
      &lt;/div&gt;
    &lt;/a&gt;
  &lt;div class="ltag__user__content"&gt;
    &lt;h2&gt;
&lt;a class="ltag__user__link" href="/racheljoyh"&gt;Rachel Humes&lt;/a&gt;Follow
&lt;/h2&gt;
    &lt;div class="ltag__user__summary"&gt;
      &lt;a class="ltag__user__link" href="/racheljoyh"&gt;Software developer and avid salsa dancer, who is equally comfortable busting a move on the dance floor and building full stack scalable and efficient web applications.&lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How To Move Item Cards to a Favorites Page in React</title>
      <dc:creator>Anna Q. Harder</dc:creator>
      <pubDate>Fri, 09 Dec 2022 19:48:20 +0000</pubDate>
      <link>https://dev.to/annaqharder/how-to-move-item-cards-to-a-favorites-page-in-react-hg5</link>
      <guid>https://dev.to/annaqharder/how-to-move-item-cards-to-a-favorites-page-in-react-hg5</guid>
      <description>&lt;p&gt;A popular feature in basic web applications is the functionality of selecting a specific item from a larger group of items and moving the selected item to another page or list. For example, on a shoe store website, a user can select a pair of shoes from a list of shoes on the homepage, and add that pair of shoes to their cart.&lt;/p&gt;

&lt;p&gt;This functionality was a main feature in the React web application I created for my second project in my software engineering bootcamp. I decided to write a "how to" blog post on how to build out this functionality. &lt;/p&gt;

&lt;p&gt;A little background on my project: I wanted to build a web application/database that displayed and organized ski resorts in the United States and Canada. I specifically wanted to "favorite" a ski resort and see that "favorited" ski resort in my Favorites page. I also wanted to add functionality to remove that ski resort from the Favorites page by "unfavoriting" the resort. &lt;/p&gt;

&lt;h2&gt;
  
  
  db.json
&lt;/h2&gt;

&lt;p&gt;I created my own db.json with the top 135 ski resorts in the US and Canada. There is a specific key:value pair in my ski resort object dedicated to "favorite". The value of the "favorite" key is defaulted to "false" meaning the ski resort is not a favorite of the user. This key:value pair is a boolean because I wanted the boolean to switch to true once the user "favorited" the ski resort. Furthermore, a boolean easily allowed me to insert conditional rendering later in my code. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I wanted the favorite/unfavorite functionality to persist when the webpage reloads. Therefore, a boolean for the favorite/unfavorite feature was required in the database, as well as a PATCH request (discussed later) was needed to update the database.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z430wkegksyu673ubsu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z430wkegksyu673ubsu.png" alt="example of a ski resort object in my database"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  React Components
&lt;/h2&gt;

&lt;p&gt;I separated my React components as follows: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4l8ztpmdwv3sxfhyh6g5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4l8ztpmdwv3sxfhyh6g5.png" alt="component tree"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;**Disclaimer:&lt;/em&gt;* It's best practice to avoid duplicative components in React, however, at the time of publishing this blog post, I hadn't yet refactored my code, so there are duplicative components. &lt;/p&gt;

&lt;p&gt;The ResortCard component was the component I rendered in both the ResortList and Favorites components. This allowed me to "move" each individual Resort Card between the Resort List page and the Favorites page. &lt;/p&gt;

&lt;h2&gt;
  
  
  App Component
&lt;/h2&gt;

&lt;p&gt;In the App component, I set state for all of the resorts via the useState hook and then used the useEffect hook for a GET request to fetch my data from my db.json. I then passed "resorts" down as a prop to both the ResortList and Favorites components.&lt;br&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgfwzni64v2maue4a1hgp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgfwzni64v2maue4a1hgp.png" alt="App component"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; For now, ignore the lines 19-29 and the onFavoriteResort prop - this function will be discussed later! &lt;/p&gt;

&lt;h2&gt;
  
  
  ResortList Component
&lt;/h2&gt;

&lt;p&gt;In the ResortList component, I mapped over the resort prop I sent down from the App component, and returned a ResortCard for each resort from the original array. Because each resort is an object, a key prop was added.&lt;br&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foc8o9yem0rkx9fb5456j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foc8o9yem0rkx9fb5456j.png" alt="ResortList component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Favorite Component
&lt;/h2&gt;

&lt;p&gt;In the Favorite Component, I filtered over each resort and returned the "favorite" key:value pair. I targeted this key:value pair because it holds the boolean of whether the user has favorited the specific resort. I then mapped over that array and returned the same ResortCard. Once again, a key prop was added. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff555xynws19gtmpk5es6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff555xynws19gtmpk5es6.png" alt="Favorite component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ResortCard Component
&lt;/h2&gt;

&lt;p&gt;In the ResortCard component, I first destructured the resort prop that was originally passed from the App component through the ResortList and Favorite components (line 6). I then added each prop to the card (line 26-51) so the resort data would populate the card.&lt;/p&gt;

&lt;p&gt;Code for prop deconstruction and setting state: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjj972nr1fy7t662t6brl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjj972nr1fy7t662t6brl.png" alt="Code 1-6"&gt;&lt;/a&gt; &lt;br&gt;
Code for the rendered Resort Cards:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F100w9xd03bo8b927hfxc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F100w9xd03bo8b927hfxc.png" alt="Lines 26-51"&gt;&lt;/a&gt;&lt;br&gt;
An example of the rendered Resort Cards to the webpage: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh82lbr1a7l4fp8f50ysg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh82lbr1a7l4fp8f50ysg.png" alt="Resort Card examples"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once each card was made for each resort, I focused on the "favorite/unfavorite" functionality: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;State was set for favorite element, and "favorite" key:value pair of the resort object was set in the useState hook because I want the boolean value to reflect the DOM's state. &lt;/li&gt;
&lt;li&gt;I then set up my PATCH request within the handleFavoritedChange function, which first changed the favorite state of the resort to the opposite boolean value that was in the database (ex: in the database, the boolean is false, it would then be change to true) (line 13). &lt;/li&gt;
&lt;li&gt;Then in line 19, the database was updated to reflect the state of the ResortCard. This PATCH request function was connected to an onClick event listener, so when the empty star icon was clicked/unclicked, the handleFavoriteChange function would run. &lt;/li&gt;
&lt;li&gt;In line 22, the callback function "onFavoritedResort" was called. This callback function updates the DOM, so when the star icon is clicked to "favorite" a resort, that resort card is moved to the Favorite Page. And when a resort card is "unfavorited", the resort card leaves the Favorite Page. &lt;/li&gt;
&lt;li&gt;handleFavoritedResort callback function was passed down through ResortList and Favorites components from the App Component (I promised this function would be important!)
handleFavoriteResort function lives in the App component:
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgtt38j9bprj5665q2w71.png" alt="handleFavoriteResort callback function"&gt;
&lt;/li&gt;
&lt;li&gt;handleFavoriteResort function returns a new array which mapped over the original resort array. If the id of the favorited resort matches the resort id, then that resort is moved the updated array. The updated array (that contains the favorited resorts) is the parameter to the setResort setter function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full code for the ResortCard component: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0tuei86owbmmgp3dtkkd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0tuei86owbmmgp3dtkkd.png" alt="ResortCard component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;I added some conditional rendering via ternary operator to my onClick button (line 29-37), so the star icon would be filled in when the resort card was favorited, and an empty star would appear when a resort was unfavorited. &lt;/p&gt;

&lt;h2&gt;
  
  
  Final Product
&lt;/h2&gt;

&lt;p&gt;The favorite/unfavorite functionality has now been built out! Here's how this functionality works:&lt;/p&gt;

&lt;p&gt;All Resorts page with no resorts favorited: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fay8l812sdfzqmrczeli9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fay8l812sdfzqmrczeli9.png" alt="Tutorial 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All Resorts page with Alyseka Resort favorited (star is yellow):&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2vo5m7ftr252fynybzaj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2vo5m7ftr252fynybzaj.png" alt="Tutorial 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Favorites page with Alyseka Resort populated: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx74r5d19t87b4eroppvo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx74r5d19t87b4eroppvo.png" alt="Tutorial 3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When Alyseka Resort is unfavorited, the resort card is removed from the Favorites page, but still appears in the All Resorts page. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I started learning React 3 weeks ago, so the feeling of excitement and accomplishment when figuring out this functionality is the reason why I am so passionate about coding and software development. This functionality was one of the first major examples of being able to implement one of my ideas into a workable feature. &lt;/p&gt;

&lt;p&gt;The favorite/unfavorite functionality can be used in many different scenarios, so I hope this tutorial was helpful! &lt;/p&gt;

&lt;p&gt;As always, there are infinite ways to code, so I am sure there are many other ways to create this function. Please let me know if there are areas where I can improve my code!&lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Demystifying .innerText vs. .textContent</title>
      <dc:creator>Anna Q. Harder</dc:creator>
      <pubDate>Thu, 17 Nov 2022 22:05:29 +0000</pubDate>
      <link>https://dev.to/annaqharder/demystifying-innertext-vs-textcontent-35fl</link>
      <guid>https://dev.to/annaqharder/demystifying-innertext-vs-textcontent-35fl</guid>
      <description>&lt;p&gt;Learning JavaScript is a challenging feat. For me, one of the most mystifying parts of JavaScript was determining when to use &lt;strong&gt;innerText&lt;/strong&gt; vs. &lt;strong&gt;textContent&lt;/strong&gt; because both methods return the text contained within a DOM tree node. I was under the impression that innerText and textContent were interchangeable. However, this is not the case - rather, there are important differences between the two. &lt;/p&gt;

&lt;p&gt;There are two objectives of this blog post: &lt;br&gt;
1) Explain key differences between the innerText and textContent properties &lt;br&gt;
2) demonstrate the occasions when each property should be called &lt;/p&gt;

&lt;h2&gt;
  
  
  .textContent
&lt;/h2&gt;

&lt;p&gt;textContent returns the raw textual content inside the DOM node and its descendants, including script and style tags. textContent is aware of formatting such as spacing and line breaks. &lt;/p&gt;

&lt;p&gt;🌟 &lt;strong&gt;TLDR:&lt;/strong&gt; Use textContent when you want to see what's in the element &lt;strong&gt;including&lt;/strong&gt; the relevant styling. &lt;/p&gt;

&lt;h2&gt;
  
  
  .innerText
&lt;/h2&gt;

&lt;p&gt;innerText is aware of the rendered appearance of the text content of a node and its descendants. This means when using this property, innerText will only show human-readable elements (i.e., innerText will roughly return what you would get if you selected and copied the text on the page to the clipboard). Furthermore, innerText cannot access the contents of script or style tag elements. &lt;/p&gt;

&lt;p&gt;🌟 &lt;strong&gt;TLDR:&lt;/strong&gt; Use innerText when you only need to see what's in the element &lt;strong&gt;without&lt;/strong&gt; the formatting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Visual Explanation
&lt;/h2&gt;

&lt;p&gt;I'm a visual learner, so I think the best way to understand the differences between innerText and textContent is through code examples. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example #1&lt;/strong&gt;&lt;br&gt;
In the HTML code below, notice the indentation after the colon &lt;strong&gt;:&lt;/strong&gt; and the "display: none" styling within the span element. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hfbfiw1isnry52gp9ul.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hfbfiw1isnry52gp9ul.png" alt="HTML and JavaScript code with innerText and textContent"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When using &lt;strong&gt;textContent&lt;/strong&gt;, this method extracts the text from within the paragraph as it exists in the markup - the line break, indentation, and placeholder text are preserved. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxot5aab3b6hswlaimk1p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxot5aab3b6hswlaimk1p.png" alt="result when using textContent"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the other hand, when using &lt;strong&gt;innerText&lt;/strong&gt;, the placeholder text is missing which means the "display: none" styling was taken into account, and there is no second line.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdx1yefnoxi8jfvb969wj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdx1yefnoxi8jfvb969wj.png" alt="result when using innerText"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;innerText&lt;/strong&gt; returns what is rendered to the page, as it appears to the human eye. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5icnlirxtudu05dtrzk6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5icnlirxtudu05dtrzk6.png" alt="text rendered to the page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example #2&lt;/strong&gt;&lt;br&gt;
The use of innerText vs. textContent is also important when there is a multi-line string, such as a physical address. &lt;/p&gt;

&lt;p&gt;In the code below, &lt;strong&gt;textContent&lt;/strong&gt; is used to render the address to the DOM. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fycsya95zf8l6cqdgwobz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fycsya95zf8l6cqdgwobz.png" alt="textContent"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;textContent&lt;/strong&gt; renders the text in a single line: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffxvtvirdx3l08ounmswx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffxvtvirdx3l08ounmswx.png" alt="textContent rendering"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alternatively, seen in the code below, &lt;strong&gt;innerText&lt;/strong&gt; is used to render the address to the DOM.&lt;br&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp46itetqxngicqcw06xk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp46itetqxngicqcw06xk.png" alt="innerText"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;innerText&lt;/strong&gt; preserves the multi-line formatting: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu5dlr32mqbx65u62l800.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu5dlr32mqbx65u62l800.png" alt="innerText rendering"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;textContent and innerText methods have specific uses depending on what you want your code to accomplish. Keep in mind that &lt;strong&gt;innerText&lt;/strong&gt; can introduce performance problems especially when used inside a loop or other iterative method, but these performance slowdowns are avoidable by using textContent. &lt;/p&gt;

&lt;p&gt;There are a ton of other blog posts and videos also explaining the differences between innerText and textContent methods, but I hope this post provides an additional explanation between these two JavaScript methods. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
