<?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: marthaeochoa</title>
    <description>The latest articles on DEV Community by marthaeochoa (@marthaeochoa).</description>
    <link>https://dev.to/marthaeochoa</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%2F986223%2F86674ce2-0e3b-43dc-b0d8-db96e98b3924.png</url>
      <title>DEV Community: marthaeochoa</title>
      <link>https://dev.to/marthaeochoa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marthaeochoa"/>
    <language>en</language>
    <item>
      <title>React information flow.</title>
      <dc:creator>marthaeochoa</dc:creator>
      <pubDate>Mon, 06 Mar 2023 18:18:22 +0000</pubDate>
      <link>https://dev.to/marthaeochoa/react-information-flow-4jem</link>
      <guid>https://dev.to/marthaeochoa/react-information-flow-4jem</guid>
      <description>&lt;p&gt;So we know to pass information from a parent down to a child we use props. Well, as it turns out, to do the opposite: it is NOT that simple.&lt;/p&gt;

&lt;p&gt;So how can we send information from a child component to its parent component? You would only need to pass information from a child to a parent component when something happening in the child component directly affects the parent. Take a delete button for example. A delete button that removes something from the application.&lt;/p&gt;

&lt;p&gt;The way we would handle this is by creating a callback function in the parent component and passing it down to the child as a prop. &lt;br&gt;
In my application, I needed to make a delete button functional, but the delete button lives in a nested child component.&lt;/p&gt;

&lt;p&gt;So I have app&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function app () {
 const [projects, setProjects] = useState([]);
return (
&amp;lt;ProjectList projects={projects} /&amp;gt;
)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And ProjectList which returns all the projects I want to display in my application (with props passed down by app).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ProjectList ({ projects}) {

    return projects.map(project =&amp;gt; {
        return (
        &amp;lt;ProjectItem 
        key={project.id} 
        project={project} 
        /&amp;gt;
     )
    })
};

return (
          &amp;lt;section&amp;gt;
            &amp;lt;table&amp;gt;
            &amp;lt;tr&amp;gt;
                    &amp;lt;td&amp;gt;&amp;lt;h3&amp;gt;Title&amp;lt;/h3&amp;gt;&amp;lt;/td&amp;gt;
                    &amp;lt;td&amp;gt;&amp;lt;h3&amp;gt;Description&amp;lt;/h3&amp;gt;&amp;lt;/td&amp;gt;
             &amp;lt;/tr&amp;gt;
             {renderProjects(projects)}
            &amp;lt;/table&amp;gt;
        &amp;lt;/section&amp;gt;
)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I created a table to better fit my layout, but as you can see, I created a seperate component to take care of each individual Project in my list of projects. That component looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ProjectItem({ project }) {

    const { id, title, description } = project 

    return(
       &amp;lt;tr&amp;gt;
        &amp;lt;td&amp;gt;{title}&amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;{description}&amp;lt;/td&amp;gt;
        &amp;lt;td className="delete-button"&amp;gt;
            &amp;lt;button className="delete-button"&amp;gt; x &amp;lt;/button&amp;gt;
        &amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in order to make my delete button functional, I need to get the click to reach all the way to the app component since Projects state lives in app. The app component displays ProjectList and ProjectList needs ProjectListItem in order to display each project. So let's create the call back function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function app () {
const [projects, setProjects] = useState([]);

  function onProjectDelete (projectId) {
    setProjects(projects =&amp;gt; projects.filter(Project =&amp;gt; Project.id !== projectId))
};

return (
&amp;lt;ProjectList projects={projects} onProjectDelete={onProjectDelete} /&amp;gt;
)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then accept it in our ProjectList component and pass it down to our ProjectItem component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ProjectList ({ projects, onProjectDelete }) {

    return projects.map(project =&amp;gt; {
        return (
        &amp;lt;ProjectItem 
        key={project.id} 
        project={project} 
        onProjectDelete={onProjectDelete}
        /&amp;gt;
     )
    })
};
.......
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we accept it in our ProjectItem component. We now must create a function that will take in onProjectDelete and be handled by the onClick event.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ProjectItem({ project, onProjectDelete }) {

    const { id, title, description } = project 

    function handleDelete () {
        onProjectDelete(id);
    }

    return(
       &amp;lt;tr&amp;gt;
        &amp;lt;td&amp;gt;{title}&amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;{description}&amp;lt;/td&amp;gt;
        &amp;lt;td className="delete-button"&amp;gt;
            &amp;lt;button className="delete-button" onClick={handleDelete}&amp;gt; x &amp;lt;/button&amp;gt;
        &amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there we have sucessfully created a way to connect the information happening in ProjectItem all the way back up to state in the App component.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>vscode</category>
    </item>
    <item>
      <title>The Dreaded Phase 1 Assessment</title>
      <dc:creator>marthaeochoa</dc:creator>
      <pubDate>Wed, 21 Dec 2022 21:29:03 +0000</pubDate>
      <link>https://dev.to/marthaeochoa/the-dreaded-phase-1-assessment-34pa</link>
      <guid>https://dev.to/marthaeochoa/the-dreaded-phase-1-assessment-34pa</guid>
      <description>&lt;p&gt;If you're just starting out phase 1, or you're almost done and you're getting ready for your phase 1 assessment, then I'm sure you are &lt;em&gt;&lt;strong&gt;dreading&lt;/strong&gt;&lt;/em&gt; it.&lt;br&gt;
From the moment I started this program I was so scared of this assessment because I think we are naturally afraid of the unknown. So I will be sharing some tips on how to prepare yourself for this assessment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepare Technically
&lt;/h2&gt;

&lt;p&gt;If you're asynchronous, it is so important you pace yourself and take time to actually understand what you're reading and understanding the "why's" of the labs you're working on. It is also super important to study and touch up on topics you probably didn't even look twice at since completing. STUDY! Don't try to cram because I promise you will forget something. Take time each day to study a little bit and look back on previous topics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepare Mentally
&lt;/h2&gt;

&lt;p&gt;The first thing the instructor asked me was "How are you?" to which I replied, "Oh, I am so nervous". She then told me something that soothed my nerves a little bit and that was "This isn't like a normal school test, this is kind of like a mock interview."&lt;br&gt;
Now, I am great at interview, but I still did not know what a technical interview would look like. So let me tell you what this one might look like:&lt;br&gt;
&lt;em&gt;Have your project already running.&lt;/em&gt; You don't want to waste time and take time away from your live coding.&lt;br&gt;
You will want to also have your project GitHub repo open. &lt;br&gt;
You will walk through your code, the instructor may ask any questions they like about your code and ask for you to name or point out certain things e.g(callback functions, "what does this code do", "what is this section called").&lt;br&gt;
After this, you will do the live coding. The instructors are there to guide you, they don't just silently sit there and watch you code so don't make them sit and watch you silently code. It's not a who-can-talk-less contest. Talk through your code, talk through what you're doing. Your instructor might say little words of encouragement or even "okay try it" to guide you the right way. They want you to pass, they just have to know what you're thinking in order to help you pass. &lt;br&gt;
Get help from your cohorts, we honestly are in this together, and once we realize that, the better. We all want to make it, and by working together you ensure each other's success and already made connections with people in the same field as you. &lt;/p&gt;

&lt;p&gt;This assessment is nothing to cry about nor is it something to be afraid of, I know that now. &lt;/p&gt;

</description>
      <category>flatironschool</category>
      <category>livecoding</category>
      <category>javascript</category>
    </item>
    <item>
      <title>My Problem with Asynchronous Code</title>
      <dc:creator>marthaeochoa</dc:creator>
      <pubDate>Wed, 07 Dec 2022 20:20:07 +0000</pubDate>
      <link>https://dev.to/marthaeochoa/my-problem-with-asynchronous-code-200o</link>
      <guid>https://dev.to/marthaeochoa/my-problem-with-asynchronous-code-200o</guid>
      <description>&lt;p&gt;When working on my simple application, one thing I kept forgetting about and continued to struggle with was &lt;em&gt;asynchronous code&lt;/em&gt; and the things I could and couldn't do with it. &lt;br&gt;
I struggled to find a reason as to why my buttons were not working the way they should have been. Forget working, the buttons were not even active! It was as if I was trying to call a button that did not exist...&lt;br&gt;
I grew frustrated, and one thing I should have done earlier was ask for help, because once I recevied help, I realized that my problem had such a simple fix; If I had only remembered asynchronous code.&lt;/p&gt;

&lt;p&gt;You see, I got so used to synchronous coding and how with that, its so easy. If it's on the page, it exists. With synchronous coding, your code runs line by line, top to bottom. &lt;br&gt;
So for example...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const puppies = "Thor and Hela"
console.log(puppies)
// Thor and Hela
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are able to get back the result because the code is synchronous. &lt;br&gt;
But, what I was trying to do was call &lt;em&gt;"puppies"&lt;/em&gt; in a place where &lt;em&gt;"puppies"&lt;/em&gt; was not real yet.&lt;/p&gt;

&lt;p&gt;My real example consisted of using fetches. In my application, I created a GET fetch in order to obtain information from a db.json file. Once I did that, I created HTML elements for the information I received to be rendered on to my application. This included an &amp;lt; h2 &amp;gt;, &amp;lt; div &amp;gt;, two &amp;lt; p &amp;gt;, and a &amp;lt; button &amp;gt;. Like so..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function renderData(data){
let data = document.createElement('li')
data.innerHTML = `
&amp;lt;div id="content"&amp;gt;
    &amp;lt;h2&amp;gt;${data.firstValue}&amp;lt;/h2&amp;gt;
    &amp;lt;p&amp;gt;Second Value: ${data.secondValue} &amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt;Third Value: ${data.thirdValue}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="button"&amp;gt;
    &amp;lt;button&amp;gt;Click!&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
    `
document.querySelector('#data-list').appendChild(data)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This alone, worked perfectly! It displayed all the information on my page! Great!! Now all I needed was to get that button to click! So how about adding an event listener? Sounds good, right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;button&amp;gt;Click!&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
    `
document.querySelector('#data-list').appendChild(data)
}

const button = document.getElementsByClassName("button")
button.addEventListener("Click", ()=&amp;gt;{
alert('You clicked me!')
}

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

&lt;/div&gt;



&lt;p&gt;Great! What could possibly go wrong?&lt;/p&gt;

&lt;p&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%2Fi3wjhwnpwei6s2t58h32.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%2Fi3wjhwnpwei6s2t58h32.png" alt="Image description" width="588" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, in this moment I felt like Javascript made a mistake! In all it's time being a reliable coding language, it made its first mistake with me. Little did I know that the one that made the mistake was actually me, and not the very reliable coding language. I was shocked! It took me a long time and a lot of stress to finally have the courage to ask a cohort&lt;br&gt;
"Can you take a look at my code and see if there's something wrong here?"&lt;br&gt;
Let me tell you, he took one look at my code and immediately said &lt;br&gt;
"Oh, I see what you did" &lt;br&gt;
I was so embarrassed, but he was so helpful and he helped me see the error of my ways. Not by telling me "hey you shouldn't have done this, you should've done this instead" but by saying "How comfortable are you with asynchronous code?" He then walked me through what he meant and helped me debug some things before I came to my own realization of what I had to do. The answer was so simple. &lt;/p&gt;

&lt;p&gt;Because I created the button tag as a result of my GET request, the button doesn't technically exist to the rest of my code. The button tag only exists within the renderData function. In order for my event listener to be able to listen for a button, is by having it listen to the button where the button lives.&lt;br&gt;
Turning my code into this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function renderData(data){
let data = document.createElement('li')
data.innerHTML = `
&amp;lt;div id="content"&amp;gt;
    &amp;lt;h2&amp;gt;${data.firstValue}&amp;lt;/h2&amp;gt;
    &amp;lt;p&amp;gt;Second Value: ${data.secondValue} &amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt;Third Value: ${data.thirdValue}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="button"&amp;gt;
    &amp;lt;button&amp;gt;Click!&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
    `
document.querySelector('#data-list').appendChild(data)

 const button = document.getElementsByClassName("button")
 button.addEventListener("Click", ()=&amp;gt;{
 alert('You clicked me!')
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once I moved the event listener to inside the renderData function, I was then able to successfully grab the button and add an event listener to it. If I tried to call that event listener anywhere else, it simply would not be able to grab that button.. no matter how many times you try it out in the console...&lt;/p&gt;

&lt;p&gt;The fact that the renderData function was only activated by the GET request promise, is what makes that function asynchrounous. It doesn't run in order in which it is written. It won't run until the GET request is complete. Therefore, the button doesn't exist outside of that function. &lt;/p&gt;

&lt;p&gt;This experience helped me understand asynchrounous code a little better, don't get me wrong, it is still a complicated concept. You just need to experience that error in order to open your eyes and see what asynchronous code actually looks like.&lt;/p&gt;

</description>
      <category>learning</category>
    </item>
  </channel>
</rss>
