<?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: Yasin</title>
    <description>The latest articles on DEV Community by Yasin (@yasin162).</description>
    <link>https://dev.to/yasin162</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%2F795793%2Fd3a1a71e-6715-478a-8878-070520d4485c.jpeg</url>
      <title>DEV Community: Yasin</title>
      <link>https://dev.to/yasin162</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yasin162"/>
    <language>en</language>
    <item>
      <title>How to do a delete request in react</title>
      <dc:creator>Yasin</dc:creator>
      <pubDate>Wed, 19 Jan 2022 20:17:19 +0000</pubDate>
      <link>https://dev.to/yasin162/how-to-do-a-delete-request-in-react-1lf7</link>
      <guid>https://dev.to/yasin162/how-to-do-a-delete-request-in-react-1lf7</guid>
      <description>&lt;p&gt;Before check to make sure your backend is set up correctly before starting. Meaning your routes has a destroy route and the controller has the method.&lt;/p&gt;

&lt;p&gt;Make a function that every single time it's run fetches and deletes the object you want delete. So in my case I call it deletePost with the parameters of postId. That way it will match whatever route that is has the corresponding postId.&lt;/p&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%2Fmhtcw7g6553c4n74ddic.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%2Fmhtcw7g6553c4n74ddic.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make a button that has an onClick with an anonymous function that takes in the function you just made and past through the data needed for the function. So in my situation it was a post.Id.&lt;/p&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%2Fzlkqwwgi0lcbd1awsvsu.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%2Fzlkqwwgi0lcbd1awsvsu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>A quick start to using or context (global state) in react</title>
      <dc:creator>Yasin</dc:creator>
      <pubDate>Wed, 19 Jan 2022 19:26:16 +0000</pubDate>
      <link>https://dev.to/yasin162/a-quick-start-to-using-or-context-global-state-in-react-2f47</link>
      <guid>https://dev.to/yasin162/a-quick-start-to-using-or-context-global-state-in-react-2f47</guid>
      <description>&lt;p&gt;Before even using global state make sure it's a state that majority of your app is gonna use. If it's just for 2 components for example, you'd just want to use state at the parent level. Then pass it down to the child component as a prop.&lt;/p&gt;

&lt;p&gt;If you find yourself making redundant states, that's a good sign that you should use global state. First Thing to do is make a file and call it whatever you want it to be. I had mine in a folder called context because I had more than one global state and I named it "globalPost.js".&lt;/p&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%2Fsk5bpp1skxcvzhpc4ng0.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%2Fsk5bpp1skxcvzhpc4ng0.png" alt="Make and name the file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next import React, useState, and if you are fetching from another place useEffect.&lt;/p&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%2Fr2n1075vvaqh39mghcqj.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%2Fr2n1075vvaqh39mghcqj.png" alt="Import the hooks you need"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that create and name the context of your context. Outside of your provider function. Then create your provider function and pass down children as a prop.&lt;/p&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%2Ffqo2lry7b9kesa6fak0p.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%2Ffqo2lry7b9kesa6fak0p.png" alt="create the context and provider"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then inside the provider function name the state whatever you it to be. In my case I am calling it posts and setting it equal to an empty area. Then using useEffect open first mounting to fetch my post data and setting my posts state to the data I just fetched.&lt;/p&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%2Fmrfoy3oc87689lep6v66.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%2Fmrfoy3oc87689lep6v66.png" alt="Make and set the state"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now in the return of the provider function render .provider on your context that you just made and set the value equal to the state that you want to use in other components. Also in between the context provider in curly brackets call children. Then export your context and your provider.&lt;/p&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%2Fcx72rvgr2wn509ko84iw.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%2Fcx72rvgr2wn509ko84iw.png" alt="Render and export context and provider"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Import your provider to the highest level component you need it at. So if you need it throughout the entire app render it in the index.js file.&lt;/p&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%2Fsv29qtesg9i4e1t2rq08.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%2Fsv29qtesg9i4e1t2rq08.png" alt="Import provider to highest level component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly you can use it on any component throughout the entire app by importing useContext, and then import your context. Then calling it inside your function component.&lt;/p&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%2Ftiawc77bknubhk21keek.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%2Ftiawc77bknubhk21keek.png" alt="Import context in component that needs ir"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
