<?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: rayzana280</title>
    <description>The latest articles on DEV Community by rayzana280 (@rayzana280).</description>
    <link>https://dev.to/rayzana280</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%2F1036839%2F4eeda6c2-8520-48f2-a1f0-93e559999e82.png</url>
      <title>DEV Community: rayzana280</title>
      <link>https://dev.to/rayzana280</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rayzana280"/>
    <language>en</language>
    <item>
      <title>Event Handler onClick</title>
      <dc:creator>rayzana280</dc:creator>
      <pubDate>Wed, 19 Jul 2023 18:41:34 +0000</pubDate>
      <link>https://dev.to/rayzana280/event-handler-onclick-1d0c</link>
      <guid>https://dev.to/rayzana280/event-handler-onclick-1d0c</guid>
      <description>&lt;p&gt;While coming to the end of Phase 2 in Flatiron School, React is a big topic that could be talked about for hours or even days. But it's an important thing to learn about. React is a library that lets you build user interfaces out of components. Components are reusable code that take in props and return react elements(JSX). Now that we have an image on what react and what a component is now we can talk about &lt;strong&gt;events&lt;/strong&gt;. Since React is built entirely out of javascript we are still handling html like elements. As you guessed it &lt;strong&gt;events&lt;/strong&gt; are the same as event listeners. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1
&lt;/h2&gt;

&lt;p&gt;There are few event handlers you could use such as onSubmit, onChange, onClick, onFocus etc. But to have a better understanding will start with onClick. First we need to add what event handler we are using on the JSX and that would be the button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x2jecWGB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yef4zh725r0k0mm73np2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x2jecWGB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yef4zh725r0k0mm73np2.jpg" alt="Image description" width="800" height="632"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An event handler will be triggered when the user interacts with the button since we are using the onClick event. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2
&lt;/h2&gt;

&lt;p&gt;Now since we are passing the event handler in the JSX element, we have to make a callback function for what we want the button to do when a user clicks on the button. So we are going to create a callback function called clicking for the button and have it console.log "button has been clicked".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ec4yA9PK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u26xv5lvuj3s262m0kht.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ec4yA9PK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u26xv5lvuj3s262m0kht.jpg" alt="Image description" width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that we have the callback function, we have to add this callback function to the event handler. After adding the callback function, now when we click the button the event handler will invoke the callback function to console.log "button has been clicked".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oO98IKyf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wpafz49970528jo014wc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oO98IKyf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wpafz49970528jo014wc.jpg" alt="Image description" width="800" height="142"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how you could use an event handler of onClick. Pretty simple and there are many ways you could use this button, but let's get into more depth on what you could do with the onClick button. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CallBack Props&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You don't have to make the callback function in the same component as your event handler is being used. You could use the callback function from a different component and use it in the component where your event handler is being used. In order to make this happen we need to pass the callback function as a prop. But we could only pass down props from the parent component. Right now my parent component is the App component, so we can create the same function clicking as a prop called "buttonClicked". &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zUV0Mwss--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pahq4g4lsp31pxav5334.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zUV0Mwss--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pahq4g4lsp31pxav5334.jpg" alt="Image description" width="800" height="643"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Back to the Click component, now we will be able to use the buttonClicked prop and get the console.log("button has been clicked").&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HnQlZPYd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5inufy0o68hm12sfw2ae.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HnQlZPYd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5inufy0o68hm12sfw2ae.jpg" alt="Image description" width="800" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameter&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For the event handler callback function, the callback takes a parameter. The parameter would be "e":&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ehp1o52x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aukadp0oxbub6ox79psm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ehp1o52x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aukadp0oxbub6ox79psm.jpg" alt="Image description" width="800" height="651"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What this parameter will do is give you the information about the event handler. We have the parameter set up already lets console.log the parameter and is the information of the event handler.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6s9uieVg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b5b56vvm08jrcegtqcmp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6s9uieVg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b5b56vvm08jrcegtqcmp.jpg" alt="Image description" width="800" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are using onChange or onSubmit this parameter will be used a lot , so it is a good idea to get very familiar with this parameter and learn what information you access while using these event handlers. One major information you could access is the value of the event. The value of what the user is submitting or the changes the user is doing.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Blog Phase 1</title>
      <dc:creator>rayzana280</dc:creator>
      <pubDate>Mon, 03 Jul 2023 04:09:43 +0000</pubDate>
      <link>https://dev.to/rayzana280/blog-phase-1-44jg</link>
      <guid>https://dev.to/rayzana280/blog-phase-1-44jg</guid>
      <description>&lt;p&gt;Being a beginner to the world of Software Engineering is very challenging. Especially for the people who had absolutely zero experience in coding just like me, but after reading and being a Flatiron student I'm here to give a better understanding with communicating with the server. A built-in JavaScript method that is very important to learn, that method is Fetch. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9g0RkPqP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wsywma8ho20ysm189cev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9g0RkPqP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wsywma8ho20ysm189cev.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fetch is a built-in JavaScript method that will retrieve a promise from an API that later can be used as an JSON object. Once you have that data you will be able to use the data depending on its usage. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;"Fetch()" takes one argument and that's the api path you want to fetch. Here we are using a API that will gives random cat facts. It will look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ySKSQhmK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0xvmrnaubk7cu5m13y7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ySKSQhmK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0xvmrnaubk7cu5m13y7.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;what we are doing here is basically using the url as an argument for fetch and what we are receiving back is a promise. To see if we are getting a promise back we "console.log()" the the "fetch()".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--07awjmgj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5vrzjt7ag6o46nz9dtwy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--07awjmgj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5vrzjt7ag6o46nz9dtwy.png" alt="Image description" width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once we have a promise we have to resolve this into to response to then later turn into an JSON object. But right now we have to resolve the promise and we are going to use a promise method which is ".then()". The method ".then" takes in an argument response. Now let's make sure we are getting a response back. We could make sure we are getting a response back by doing another on "console.log".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vs71tsKO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g2xmy8uq7semrouvviy1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vs71tsKO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g2xmy8uq7semrouvviy1.png" alt="Image description" width="800" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have a response object we won't be able to use it the way we want it to because it isn't a "JSON" object since we are working with JSON data. Now we are going to use a method which converts it to an "JSON" object and that's ".json()" .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GBkrTIO9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6nlcp7196mzwgmzkpnkc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GBkrTIO9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6nlcp7196mzwgmzkpnkc.png" alt="Image description" width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have finished using ".json()" let's not forget this will give us another promise so we are not finished yet. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After receiving another promise let us finally use that data by using another ".then" and this specific ".then" it will take an argument of data that we want to use.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KLIbEQzD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cfn53mvqnx0qr1i8zzx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KLIbEQzD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cfn53mvqnx0qr1i8zzx.png" alt="Image description" width="800" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's make sure we getting the data back by using a "console.log"&lt;/p&gt;

&lt;p&gt;Now you are able to use what you are working with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There's one more step we have to complete using the ".catch" method. By using this method javascript will be able to catch an error incase if the server fails to give us data or we aren't getting a promise, etc. Also ".catch" takes an argument which would be the error. We could "console.log" the error or we add an alert to let the user know about the error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I_DRhgQi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8551dzupu6txz3letd1m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I_DRhgQi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8551dzupu6txz3letd1m.png" alt="Image description" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see I ruined the API path so I got an alert using ".catch()"&lt;/p&gt;

&lt;p&gt;If we want to catch the error and know where this error is coming from we could use .ok to show us if the response is the error. We will use an if statement to "console.log('working')" if the response meets the condition, but we also add an else to "console.log" a message saying "no working" if the response is not working. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xgi0uT6l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9q51m2bu7lwxadq1vh0v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xgi0uT6l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9q51m2bu7lwxadq1vh0v.png" alt="Image description" width="800" height="675"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More Info On Fetch&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that you have an idea on how fetch works, let's say you want to post data, patch data and delete data, then fetch is going to take another argument which will have  us doing a few things to set up for the method we want to use. First we need to pass in an HTTP method that we are going to use. In this case we are using our own "API" and we are going to use the "POST" method. Let's not forget our data base has no data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EEQwFwBS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e7qry75hn073bijlvb8v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EEQwFwBS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e7qry75hn073bijlvb8v.png" alt="Image description" width="800" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we need to pass the body in order to "POST" what we want inside the body. The value for the body is "name: bob". After knowing what we want to post we need to "json.stringify" the object that we pass for the body. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d-gwXmWo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3czbwuvgn8mocqzyb4py.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d-gwXmWo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3czbwuvgn8mocqzyb4py.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This step on the upcoming steps are needed because without these steps, whatever you want to post will not appear on the data. Next we are going to add a headers, this is telling Fetch that we are passing "JSON". For the value we are going to pass an object and inside the Object we are going to add "Content-Type": "application/json". After following these setups we are going to see what we wanted to post on our data that we are using.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PBxbmoRE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cggj6dlwju4689w5ence.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PBxbmoRE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cggj6dlwju4689w5ence.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this short summary of "Fetch" was very useful, until next time.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
