<?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: kar7779</title>
    <description>The latest articles on DEV Community by kar7779 (@kar7779).</description>
    <link>https://dev.to/kar7779</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F373105%2F3e7cfb34-5982-48ae-ad80-1d2702b7de8c.jpg</url>
      <title>DEV Community: kar7779</title>
      <link>https://dev.to/kar7779</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kar7779"/>
    <language>en</language>
    <item>
      <title>Todo app with react-hooks</title>
      <dc:creator>kar7779</dc:creator>
      <pubDate>Sun, 08 Nov 2020 05:52:40 +0000</pubDate>
      <link>https://dev.to/kar7779/todo-app-with-react-hooks-4m5c</link>
      <guid>https://dev.to/kar7779/todo-app-with-react-hooks-4m5c</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uxRT0Iwi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9wcv5blpc2xpv8p8dy02.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uxRT0Iwi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9wcv5blpc2xpv8p8dy02.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Setup all the files :&lt;/p&gt;

&lt;p&gt;create a react app in the terminal by using this code&lt;br&gt;
&lt;code&gt;npx create-react-app todo-app&lt;/code&gt;&lt;br&gt;
after installing all dependencies by changing the directory and open that file in the code editor&lt;/p&gt;

&lt;p&gt;after creating react app go to &lt;code&gt;app.js&lt;/code&gt; in &lt;code&gt;src&lt;/code&gt; folder&lt;br&gt;
edit the &lt;code&gt;app.js&lt;/code&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Creating input form to capture the user input
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CMsDO53D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4ccm18zsyrjpkgn0w17f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CMsDO53D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4ccm18zsyrjpkgn0w17f.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above image, we used a form and an input tag in order to store the value that the user will type and a button when we click this button our todo will get visible on the web page. in order to store and maintain the state, we have to use the state management tools called &lt;strong&gt;Hooks&lt;/strong&gt; in react. By using Hooks we can maintain the state of an app very easy&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing Hooks
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P7TrH3tJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/z3hwmxqu7s0ltfklzpnc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P7TrH3tJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/z3hwmxqu7s0ltfklzpnc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In input tag we set value={value} we taken value state from react hook you can refer to the above image and here the initial value of Value is null. we have to set the new value so we use the onChange event listener when we change the input this event will get trigger and set this value to Value this whole state maintained by &lt;strong&gt;useState&lt;/strong&gt; Hook.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Todo Function
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vQAH4mHa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6vtji2rocx8uua2vzci6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vQAH4mHa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6vtji2rocx8uua2vzci6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Here we again create &lt;strong&gt;useState&lt;/strong&gt; hook for maintaining the todos that we create you can reference the above image. But here we use array in useState, because todos are list so we use array symbol in useState([]). we have to mount the todos in the div tag and we use array.map() method this method will go to each todo value that will render to h4 tag that we used to display the todo value in the web browser&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding todo by clicking button
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VG9Ew-L4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/q2qmdfb3r3e89iyaq61s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VG9Ew-L4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/q2qmdfb3r3e89iyaq61s.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;we define a method called &lt;code&gt;addtodo&lt;/code&gt; in the above image that is linked to the button which is under the input tag.in that method we use &lt;strong&gt;setTodo([...todos, value])&lt;/strong&gt; this will set value to todo and that todo will get render through map method and final result will be displayed in the web browser. we use &lt;strong&gt;...todos&lt;/strong&gt; this called &lt;strong&gt;spread operator&lt;/strong&gt; this will get all the todos which are in the array and the new input value get append with todos so we will get all our todos in the browser&lt;/p&gt;

&lt;h2&gt;
  
  
  Clearing the todo's
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--czweDGhf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/innmlb97a3xxyv7ffdsu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--czweDGhf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/innmlb97a3xxyv7ffdsu.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
After we completed the task we have to clear the todo's. So we have to update our todolist, after the h4 tag we created a button to clear the todo's. We used onClick listener so when we click that button the event gets trigger in that function we create a variable called &lt;strong&gt;newtodos&lt;/strong&gt; and we store all the todo's using spread operator refer the above image. we have to pop the array item in order to that we have to use the array. splice method, this method will take two parameters here in our case we pass the id that is linked with todo and another parameter is how many items we want to delete &lt;strong&gt;Splice(id,1)&lt;/strong&gt; after that, we again update our tod0list withs settodo hook with this newtodos &lt;strong&gt;settodo(newtodos)&lt;/strong&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Total source code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mWyCYM5k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9354ywdoj1m6xg24b7rb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mWyCYM5k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9354ywdoj1m6xg24b7rb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can get source code from here &lt;a href="https://github.com/kar7779/todo-list-with-react-hooks"&gt;https://github.com/kar7779/todo-list-with-react-hooks&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go live here &lt;a href="https://codesandbox.io/embed/github/kar7779/todo-list-with-react-hooks?codemirror=1"&gt;https://codesandbox.io/embed/github/kar7779/todo-list-with-react-hooks?codemirror=1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank You &lt;br&gt;
This is karthik🤗&lt;/p&gt;

</description>
      <category>react</category>
      <category>todolist</category>
      <category>hooks</category>
    </item>
  </channel>
</rss>
