<?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: Sarah Jones</title>
    <description>The latest articles on DEV Community by Sarah Jones (@sarahjones016).</description>
    <link>https://dev.to/sarahjones016</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%2F1058329%2F74a754a3-ec09-45ab-8bf1-23241c737f91.jpeg</url>
      <title>DEV Community: Sarah Jones</title>
      <link>https://dev.to/sarahjones016</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sarahjones016"/>
    <language>en</language>
    <item>
      <title>Cookies 🍪</title>
      <dc:creator>Sarah Jones</dc:creator>
      <pubDate>Mon, 19 Jun 2023 18:56:37 +0000</pubDate>
      <link>https://dev.to/sarahjones016/cookies-fc6</link>
      <guid>https://dev.to/sarahjones016/cookies-fc6</guid>
      <description>&lt;p&gt;Since 2020, Google has been talking about a plan for Chrome to block third-party cookies that can track user activity across many different websites. While Google’s plans for cookie disabling and deprecation have been pushed back a few times, marketers have been forced to think about what their marketing strategy would look like in a cookieless world. &lt;/p&gt;

&lt;p&gt;While the deprecation of third-party cookies would impact marketers, it would not primarily impact website developers. This is because website developers that use cookies to store login credentials, use first-party cookies to do so.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First-Party vs. Third-Party Cookies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;First-Party Cookies:&lt;/em&gt; &lt;br&gt;
First-party cookies are created and used on a single domain. Their most common uses include remembering a user’s language settings, items added to cart, and personal user data like email addresses and passwords. If first-party cookies were blocked, a user would have to sign-in every time they visited a website. They also wouldn’t be able to purchase multiple items while shopping online, because the cart would reset after every item that was added. First-party cookies are typically trusted by users (more so than third-party cookies), because they seek to improve the user experience of a website.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Third-Party Cookies&lt;/em&gt;: &lt;br&gt;
Third-party cookies are created on one domain and shared across all third-party domains that use the same tracking code. They are typically used for online-advertising purposes and placed on a website through a script or a tag. When a user receives ads or emails highlighting a product or products that they viewed online but never bought, this means that they have interacted with third-party cookies. Compared to first-party cookies, users sometimes don’t enjoy these interactions with third-party cookies. They may not find that they improve their online shopping experience, and sometimes feel like it’s an invasion of privacy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First-Party Cookies and Login Credentials Using Flask&lt;/strong&gt;&lt;br&gt;
As was mentioned previously, first-party cookies can be used for website login authentication. When utilizing Flask as a part of a website’s backend, developers can encrypt and sign a special cookie known as a session using the session module (instead of sending cookies in plain text). The session module is imported from flask, and behaves like a dictionary: &lt;code&gt;session['user_id'] = user.id&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By default, Flask manages all session data in a single cookie. It serializes all the key / value pairs that are set with session, converting them from a Python object into a big string. Whenever a key is set with the session module, Python updates the value of its session cookie to this string.&lt;/p&gt;

&lt;p&gt;When cookies are set this way, Flask signs them to prevent users from tampering with them. Flask servers have a key, configured in their app (app.secret_key='Example_Key'). When given the same message and same secret key, Flask will produce the same output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Ultimately, the deprecation of third-party cookies will impact marketers more than it will website developers. However, it is important for developers to understand third-party cookies' uses, because they may be responsible for adding or removing those scripts / tags from a website.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;br&gt;
"Authenticating Users." Canvas - Flatiron School, Accessed 19 June 2023.&lt;br&gt;
"Cookies and Sessions." Canvas - Flatiron School, Accessed 19 June 2023.&lt;br&gt;
Lane, Patrick. "First-Party Cookies vs. Third-Party Cookies (Biggest Differences)." &lt;em&gt;Terakeet&lt;/em&gt;, 4 Feb. 2022, &lt;br&gt;
&lt;a href="https://dev.tourl"&gt;terakeet.com/blog/first-party-cookies-vs-third-party-cookies/&lt;/a&gt;. Accessed 19 June 2023.&lt;br&gt;
Lawler, Richard. "Google's turning off third-party cookies for 1 percent of Chrome users early next &lt;br&gt;
year." &lt;em&gt;The Verge&lt;/em&gt;, 18 May 2023, &lt;a href="http://www.theverge.com/2023/5/18/23728263/google-chrome-"&gt;www.theverge.com/2023/5/18/23728263/google-chrome-&lt;/a&gt;&lt;br&gt;
ad-tracking-third-party-cookies-privacy-sandbox. Accessed 19 June 2023.&lt;br&gt;
"What's the Difference Between First and Third-Party Cookies?" &lt;em&gt;CookiePro&lt;/em&gt;, 5 Aug. 2022, &lt;br&gt;
&lt;a href="http://www.cookiepro.com/knowledge/whats-the-difference-between-first-and-third-party-cookies/"&gt;www.cookiepro.com/knowledge/whats-the-difference-between-first-and-third-party-cookies/&lt;/a&gt;. &lt;br&gt;
Accessed 19 June 2023.&lt;/p&gt;

</description>
      <category>flask</category>
      <category>cookies</category>
    </item>
    <item>
      <title>Database Constraints vs. Model Validations</title>
      <dc:creator>Sarah Jones</dc:creator>
      <pubDate>Wed, 31 May 2023 18:47:41 +0000</pubDate>
      <link>https://dev.to/sarahjones016/database-constraints-vs-model-validations-4bj0</link>
      <guid>https://dev.to/sarahjones016/database-constraints-vs-model-validations-4bj0</guid>
      <description>&lt;p&gt;When constructing a full-stack application, it’s incredibly important to validate data before it gets entered into your database. Invalid data in a database has the potential to cause a slew of problems when that data needs to be used and/or accessed. &lt;/p&gt;

&lt;p&gt;In order to prevent invalid data from being entered into a database, Flask-SQLAlchemy offers &lt;strong&gt;constraints&lt;/strong&gt; and &lt;strong&gt;validations&lt;/strong&gt; as ways in which to validate data in applications / deal with invalid data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraints&lt;/strong&gt;&lt;br&gt;
SQLAlchemy constraints allow for inputs to be controlled at a database level. To do so, they exist within models. &lt;/p&gt;

&lt;p&gt;Constraints that can be added directly to the column as it’s defined:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unique (unique=True): This constraint can be added when database values need to be unique: &lt;code&gt;name = db.Column(db.String, primary_key=True, unique=True)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Nullable (nullable=False): This constraint can be added when an input value is mandatory: &lt;code&gt;name = db.Column(db.String, primary_key=True, nullable=False)&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the example below, pet instances must include a name, and that name must be unique (i.e. does not already exist in the database’s “name” column).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Pet(db.Model):
    __tablename__ = pets
    name = db.Column(db.String, primary_key=True, nullable=False, unique=True)
    age = db.Column(db.Integer)
    animal_type = db.Column(db.String)  
    owner_email = db.Column(db.String) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Constraints that can be created for columns and/or  tables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CheckConstraints: Can use any valid SQL and numeric comparisons to validate input.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the example below, pet instances include an age, and that age must be greater than 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Pet(db.Model):
    __tablename__ = pets
    name = db.Column(db.String, primary_key=True)
    age = db.Column(db.Integer, db.CheckConstraint('age &amp;gt; 2'))
    animal_type = db.Column(db.String) 
    owner_email = db.Column(db.String)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Validations&lt;/strong&gt;&lt;br&gt;
SQLAlchemy also offers validations: special method calls that go at the top of class definitions and prevent new instances of that class from being saved to the database if their data isn’t what is expected. While both constraints and validations seek to prevent invalid data from entering a database, constraints control input at a database level whereas validations control input at a Python ORM level. &lt;/p&gt;

&lt;p&gt;In the example below, pet instances include an owner email, and that email address must contain a “@”, indicating that it is a valid email address.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Pet(db.Model):
    __tablename__ = pets
    name = db.Column(db.String, primary_key=True)
    age = db.Column(db.Integer)
    animal_type = db.Column(db.String)
    owner_email = db.Column(db.String) 

@validates('owner_email')
   def validate_owner_email(self, key, owner_email):
       if '@' not in owner_email:
            raise ValueError("Failed email validation")
       return owner_email
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Comparing Database Constraints and Model Validations&lt;/strong&gt;&lt;br&gt;
Constraints and validations have the same goal: To make sure data entering the database is valid. While they have a shared goal, it is important to understand how their functionality differs. Database constraints will always be checked when adding or updating data in the database. On the other hand, SQLAlchemy validations will only be checked when adding or updating data through the SQLAlchemy ORM. If data is added or changed some other way (i.e. SQL code via the command line), these modifications will not pass through model validations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
While constraints and validations seek to achieve the same goal, constraints come with an added level of security. To ensure invalid data doesn’t slip through the cracks, some folks write database constraints so that they mirror the model validations they’ve written. &lt;strong&gt;&lt;em&gt;TLDR&lt;/em&gt;&lt;/strong&gt;: If there is any chance that data can be added or updated via a method other than through the SQLAlchemy ORM, using database constraints is your best bet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;br&gt;
"SQLAlchemy Constraints." Canvas - Flatiron School, Accessed 31 May 2023.&lt;br&gt;
"Flask-SQLAlchemy Validations." Canvas - Flatiron School, Accessed 31 May 2023.&lt;br&gt;
coderSloth. (2020, December 22). Database Constraints, But Why? &lt;a href="https://codersloth.medium.com/database-constraints-but-why-c283761ec7c6"&gt;https://codersloth.medium.com/database-constraints-but-why-c283761ec7c6&lt;/a&gt;&lt;br&gt;
Long, N. (2017, February). Guaranteed Consistency: The Case for Database Constraints. &lt;em&gt;Big Nerd Ranch&lt;/em&gt;. &lt;a href="https://bignerdranch.com/blog/guaranteed-consistency-the-case-for-database-constraints/"&gt;https://bignerdranch.com/blog/guaranteed-consistency-the-case-for-database-constraints/&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Defining Constraints and Indexes&lt;/em&gt;. (n.d.). SQLAlchemy. Retrieved May 31, 2023, from &lt;a href="https://docs.sqlalchemy.org/en/20/core/constraints.html"&gt;https://docs.sqlalchemy.org/en/20/core/constraints.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flask</category>
      <category>python</category>
    </item>
    <item>
      <title>Creating Lists in Python: List Comprehension vs. For Loop</title>
      <dc:creator>Sarah Jones</dc:creator>
      <pubDate>Thu, 11 May 2023 17:45:21 +0000</pubDate>
      <link>https://dev.to/sarahjones016/creating-lists-in-python-list-comprehension-vs-for-loop-55bh</link>
      <guid>https://dev.to/sarahjones016/creating-lists-in-python-list-comprehension-vs-for-loop-55bh</guid>
      <description>&lt;p&gt;Considered to be the most common data structure in Python, &lt;strong&gt;lists&lt;/strong&gt; are used to store multiple items within a single variable.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;color_list = ["yellow", "green", "red"]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Because there are other ways to store data in Python, it’s important to understand what makes a list a list:&lt;/p&gt;

&lt;p&gt;A list…&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Can store all types of data&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Is indexed&lt;/strong&gt;: Each item in a list has a set location. The first item has index [0], the second item has index [1], etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Is mutable&lt;/strong&gt;: Elements within a list can be modified, individual elements can be replaced, and the order of elements can be changed even after the list has been created&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Contains items that can be repeated&lt;/strong&gt;: Because lists are indexed, they can have items with the same value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One way to create a list in Python, is by using &lt;strong&gt;a for loop&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create A List Using A For Loop&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an empty list: &lt;code&gt;name_tag_list = []&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Loop over the parameters: &lt;code&gt;for name in names:&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Append each element to the end of the list: &lt;code&gt;name_tag_list.append(f"Hello, my name is {name}.")&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Return the list, which is no longer empty: &lt;code&gt;return name_tag_list&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def nametag_creator(names):
   name_tag_list = []
   for name in names:
       name_tag_list.append(f"Hello, my name is {name}.")
   return name_tag_list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While using a for loop to create a list works (and is usually  the first list creation method you will learn), Python allows us to instantiate a list object and perform a for loop to populate its values in a single line. This can be done using &lt;strong&gt;list comprehension&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create A List Using List Comprehension&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create new list and assign its values in one line&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;List Comprehension Syntax&lt;/strong&gt;: &lt;br&gt;
&lt;code&gt;new_list = [optional_operation(item) for item in old_list if optional_condition == True]&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;optional_operation(item):  &lt;code&gt;f"Hello, my name is {name}."&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;item: &lt;code&gt;name&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;old_list: &lt;code&gt;names&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def name_tag_creator(names):
   return [f"Hello, my name is {name}." for name in names]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When comparing the two name_tag_creator functions side by side, you will see that there are a lot of similarities. In this example, utilizing list comprehension (rather than a for loop) allowed us to create a new list, iterate, and fill the new list, all at once. &lt;/p&gt;

&lt;p&gt;At this point you might be thinking, “&lt;em&gt;Wow, using list comprehension allowed us to really cut down on the number of code lines written. Why would we ever not want to use list comprehension?&lt;/em&gt;”&lt;/p&gt;

&lt;p&gt;Well, it’s always essential that we consider &lt;strong&gt;readability&lt;/strong&gt;. James Timmins says it best in his article “&lt;em&gt;When to Use a List Comprehension in Python&lt;/em&gt;”: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“While the single-line nested list comprehension might seem more Pythonic, what’s most important is to write code that your team can easily understand and modify. When you choose your approach, you’ll have to make a judgment call based on whether you think the comprehension helps or hurts readability.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Another instance where it makes sense to not utilize list comprehension, is when working with big datasets. List comprehension loads the entire output list into memory, meaning big datasets have the potential to use a lot of memory. To ensure that we don’t bog down servers, we could utilize generator expressions rather than list comprehensions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;: In Python, for loops and list comprehensions are both great ways to create a list. When you first start working in Python, I recommend you begin with a for loop. Once you have mastered how a for loop can be used to create a list, you can then transpose that into a list comprehension. Happy coding!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources&lt;/strong&gt;:&lt;br&gt;
"Intro to Data Structures." Canvas - Flatiron School, Accessed 10 May 2023.&lt;br&gt;
"List Comprehensions and Generator Expressions." Canvas - Flatiron School, Accessed 10 May 2023.&lt;br&gt;
"Python Lists." &lt;em&gt;W3Schools&lt;/em&gt;, &lt;a href="https://dev.tourl"&gt;www.w3schools.com/python/python_lists.asp&lt;/a&gt;. Accessed 11 May 2023. &lt;br&gt;
Great Learning Team, and Karuna Kumari. "Understanding Mutable and Immutable in Python." &lt;em&gt;Great Learning&lt;/em&gt;, &lt;a href="https://dev.tourl"&gt;www.mygreatlearning.com/blog/understanding-mutable-and-immutable-in-python/#:~:text=3.,the%20list%20has%20been%20created&lt;/a&gt;. Accessed 10 May 2023.&lt;br&gt;
Timmins, James. "When to Use a List Comprehension in Python." &lt;em&gt;Real Python&lt;/em&gt;, 6 Nov. 2019, &lt;a href="https://dev.tourl"&gt;realpython.com/list-comprehension-python/&lt;/a&gt;. Accessed 11 May 2023.&lt;/p&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>Controlled vs. Uncontrolled Components : Working With Forms</title>
      <dc:creator>Sarah Jones</dc:creator>
      <pubDate>Thu, 27 Apr 2023 18:30:24 +0000</pubDate>
      <link>https://dev.to/sarahjones016/controlled-vs-uncontrolled-components-working-with-forms-5ej1</link>
      <guid>https://dev.to/sarahjones016/controlled-vs-uncontrolled-components-working-with-forms-5ej1</guid>
      <description>&lt;p&gt;Just like in HTML, React uses forms as a way for users to interact with a web page. In React, components (like a form component) can be &lt;strong&gt;&lt;em&gt;controlled&lt;/em&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;em&gt;uncontrolled&lt;/em&gt;&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;When a React form's elements (&lt;code&gt;input&lt;/code&gt;, &lt;code&gt;textarea&lt;/code&gt;, &lt;code&gt;select&lt;/code&gt;)  derive their value from &lt;u&gt;state&lt;/u&gt;, the form is controlled. When a React form's elements derive their value from the &lt;u&gt;DOM&lt;/u&gt;, the form is uncontrolled. While the latter is typically how form data is handled when using HTML, the former is typically how form data is handled when using React.&lt;/p&gt;

&lt;p&gt;Below is an example of a controlled form. You will see that the value of each input field is set to a state variable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input 1: value={title}&lt;/li&gt;
&lt;li&gt;Input 2: value={author}&lt;/li&gt;
&lt;li&gt;Input 3: value={article}&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each input field then also utilizes an onChange event handler:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;onChange={(e) =&amp;gt; setTitle(e.target.value)}&lt;/li&gt;
&lt;li&gt;onChange={(e) =&amp;gt; setAuthor(e.target.value)}&lt;/li&gt;
&lt;li&gt;onChange={(e) =&amp;gt; setArticle(e.target.value)}&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These functions update the state value to reflect what is entered into each input field.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, {useState} from "react";


function NewPostForm() {


 const [title, setTitle] = useState("")
 const [author, setAuthor] = useState("")
 const [article, setArticle] = useState("")


 return (
   &amp;lt;div className="form"&amp;gt;
     &amp;lt;form&amp;gt;
       &amp;lt;input
         type="text"
         placeholder="Title"
         value={title}
         onChange={(e) =&amp;gt; setTitle(e.target.value)}
       &amp;gt;&amp;lt;/input&amp;gt;
       &amp;lt;input
         type="text"
         placeholder="Author"
         value={author}
         onChange={(e) =&amp;gt; setAuthor(e.target.value)}
       &amp;gt;&amp;lt;/input&amp;gt;
       &amp;lt;textarea
         rows="10"
         cols="60"
         placeholder="Write your post"
         value={article}
         onChange={(e) =&amp;gt; setArticle(e.target.value)}
       &amp;gt;&amp;lt;/textarea&amp;gt;
       &amp;lt;input
         className="submit-button"
         style={{ paddingBottom: "25px" }}
         type="submit"
       &amp;gt;&amp;lt;/input&amp;gt;
     &amp;lt;/form&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}


export default NewPostForm;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;When To Use Controlled Components:&lt;/strong&gt;&lt;br&gt;
At this point you might be thinking, “Sarah, I understand the difference between controlled and uncontrolled components, but so what?” Well, there are a couple of key advantages to using a controlled form in React:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sharing Form Values:&lt;/strong&gt; Because controlled form values are stored in state, values can be shared easily amongst components. One can either pass down values (parent component to child component) using props or pass up values (child component to parent component) using a callback function. This means that state does not need to be housed in the same component as the form.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Element Validation:&lt;/strong&gt; Because controlled form values are stored in state, one can set up validation functionality that a form element value must pass prior to updating the state value. This ensures that state only gets updated when values entered into  form elements meet the criteria set.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In most instances, formal React documentation recommends using controlled components to implement forms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When To Use Uncontrolled Components:&lt;/strong&gt;&lt;br&gt;
While controlled components help to ensure maximum flexibility, it may sometimes feel tedious to set them up. Especially when forms get long (and include many elements), you may question if writing an event handler and state for each element is essential. According to formal React documentation, there are a couple of situations where it may be favorable to utilize uncontrolled components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you are converting a pre-existing codebase to React&lt;/li&gt;
&lt;li&gt;When you are integrating a React application with a non-React library&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
In most cases, one should set up a React form to be controlled. While controlled forms require that state and an event handler be set up for each form element, the controlled aspect allows for form values to be used across other components with ease. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;br&gt;
"Uncontrolled Components." &lt;em&gt;Legacy React,&lt;/em&gt; legacy.reactjs.org/docs/uncontrolled-components.html. &lt;br&gt;
Accessed 26 Apr. 2023.&lt;br&gt;
"Forms." &lt;em&gt;Legacy React,&lt;/em&gt; &lt;a href="https://legacy.reactjs.org/docs/forms.html"&gt;https://legacy.reactjs.org/docs/forms.html&lt;/a&gt;. Accessed 26 Apr. 2023.&lt;br&gt;
"Sharing State Between Components." &lt;em&gt;React,&lt;/em&gt; &lt;br&gt;
react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components. Accessed 26 Apr. 2023.&lt;br&gt;
"Controlled Components." Canvas - Flatiron School, Accessed 26 Apr. 2023.&lt;/p&gt;

</description>
      <category>react</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Loop Types &amp; Working With Arrays</title>
      <dc:creator>Sarah Jones</dc:creator>
      <pubDate>Wed, 05 Apr 2023 19:08:51 +0000</pubDate>
      <link>https://dev.to/sarahjones016/loop-types-working-with-arrays-1idg</link>
      <guid>https://dev.to/sarahjones016/loop-types-working-with-arrays-1idg</guid>
      <description>&lt;p&gt;When working in JavaScript, it is inevitable that you will encounter arrays (a type of data structure). Arrays are made up of multiple elements, and often we want to perform the same action on every element in an array. While we could write out this repeated action for every element in an array, this would be incredibly tedious for arrays with lots of elements. It would also go against the software development principe of DRY (“Don't Repeat Yourself”) code.&lt;/p&gt;

&lt;p&gt;Good thing there is a better, more scalable way! That’s where loops come into play. With a loop, the repeated action only needs to be written once and it will execute on every item in the collection. &lt;/p&gt;

&lt;p&gt;There are a few different loop options (depending on the situation). Below are the three main loop types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;for loop&lt;/li&gt;
&lt;li&gt;forEach loop&lt;/li&gt;
&lt;li&gt;for ... of loop&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;for loop&lt;/strong&gt;&lt;br&gt;
The &lt;em&gt;for&lt;/em&gt; loop is the most basic of the three loop types, and takes 3 expressions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initialization: Typically used to initialize a counter variable.&lt;/li&gt;
&lt;li&gt;Condition: An expression evaluated before each pass through the loop. Whether the expression evaluates true or false determines what happens next: the statements in the loop body execute, or the loop exits.&lt;/li&gt;
&lt;li&gt;Iteration: An expression executed at the end of each iteration. This often involves incrementing or decrementing a counter.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;em&gt;for&lt;/em&gt; loop should be used when the number of times the loop should run is known.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const menuItems = ["hamburger", "pizza", "salad", "sandwich"]

for (let i = 0; i &amp;lt; menuItems.length; i++) {
  console.log(`I ordered a ${menuItems[i]}`)
}

//RETURN
// I ordered a hamburger
// I ordered a pizza
// I ordered a salad
// I ordered a sandwich
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, we set the variable “i” equal to zero. We declare the variable “i” using “let” (as opposed to “const”) because we need to increase the value of “i.” The value of “i” is increased by 1 each time the loop runs. When the value of “i” is less than the length of the menuItems array (4), the code in the code body runs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;forEach loop&lt;/strong&gt;&lt;br&gt;
In contrast with the &lt;em&gt;for&lt;/em&gt; loop, the &lt;em&gt;forEach&lt;/em&gt; and &lt;em&gt;for ... of&lt;/em&gt; loops were designed to iterate (rather than loop) over elements within an array. While looping executes a set of statements until a condition is met, iteration executes code once for each item in a collection (often elements in an array).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const menuItems = ["hamburger", "pizza", "salad", "sandwich"]

menuItems.forEach(item =&amp;gt; console.log(`I ordered a ${item}`));

//RETURN
// I ordered a hamburger
// I ordered a pizza
// I ordered a salad
// I ordered a sandwich
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see in the example above that there is no initialization of a counter, no condition, no incrementing the counter, and no bracket notation to access elements inside the menuItems array. So while &lt;em&gt;for&lt;/em&gt; loops can be used to iterate over each element in an array, using a &lt;em&gt;forEach&lt;/em&gt; (or &lt;em&gt;for … of&lt;/em&gt;) loop results in cleaner, readable code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;for ... of loop&lt;/strong&gt;&lt;br&gt;
The &lt;em&gt;forEach&lt;/em&gt; and &lt;em&gt;for ... of&lt;/em&gt; loops are similar to one another, as they both work to iterate over elements in an array.&lt;/p&gt;

&lt;p&gt;One important distinction relates to control flow; the order in which a computer executes statements in a script. The &lt;em&gt;for ... of&lt;/em&gt; loop supports normal control flow statements (like break and continue), while the &lt;em&gt;forEach&lt;/em&gt; loop does not.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Break: "jumps out" of a loop&lt;/li&gt;
&lt;li&gt;Continue: "jumps over" one iteration in the loop
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const menuItems = ["hamburger", "pizza", "salad", "sandwich"]

for (const item of menuItems) {
  console.log(`I ordered a ${item}`);
}

//Return:
// I ordered a hamburger
// I ordered a pizza
// I ordered a salad
// I ordered a sandwich
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;:&lt;br&gt;
When you first start working with JavaScript, it may initially seem like there are so many different options when it comes to looping and iterating. However, with a little practice, you too will grasp when one method should be used vs. another.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;:&lt;br&gt;
"Loops and iteration." MDN Web Docs, &lt;a href="//developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration"&gt;developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration&lt;/a&gt;. Accessed 4 Apr. 2023.&lt;br&gt;
Salvadó, Christian C. Comment on "Loop through an array in JavaScript." Stack Overflow, 10 June 2010, &lt;a href="//stackoverflow.com/questions/3010840/loop-through-an-array-in-javascript"&gt;stackoverflow.com/questions/3010840/loop-through-an-array-in-javascript&lt;/a&gt;. Accessed 4 Apr. 2023.&lt;br&gt;
"JavaScript Break and Continue." W3Schools, &lt;a href="//www.w3schools.com/js/js_break.asp"&gt;www.w3schools.com/js/js_break.asp&lt;/a&gt;. Accessed 4 Apr. 2023.&lt;br&gt;
"Looping Lab." Canvas - Flatiron School, Accessed 4 Apr. 2023.&lt;br&gt;
"Object Iteration." Canvas - Flatiron School, Accessed 4 Apr. 2023.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>arrays</category>
    </item>
  </channel>
</rss>
