<?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>Forem: Duc Le</title>
    <description>The latest articles on Forem by Duc Le (@ducdev).</description>
    <link>https://forem.com/ducdev</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%2F95567%2F14e5fa74-966a-4366-a81b-77e209f36ff6.jpeg</url>
      <title>Forem: Duc Le</title>
      <link>https://forem.com/ducdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ducdev"/>
    <language>en</language>
    <item>
      <title>Create a Todo App with React Hooks and LocalStorage</title>
      <dc:creator>Duc Le</dc:creator>
      <pubDate>Sat, 11 Jul 2020 17:08:55 +0000</pubDate>
      <link>https://forem.com/ducdev/create-a-todo-app-with-react-hooks-and-localstorage-fh1</link>
      <guid>https://forem.com/ducdev/create-a-todo-app-with-react-hooks-and-localstorage-fh1</guid>
      <description>&lt;p&gt;Creating a &lt;strong&gt;Todo App&lt;/strong&gt; is always a good idea for anyone who started learning new web technologies and want to practice with building something because it's kinda a simplest &lt;strong&gt;CRUD&lt;/strong&gt; app.&lt;/p&gt;

&lt;p&gt;I've been making a &lt;strong&gt;Todo App&lt;/strong&gt; with &lt;strong&gt;React Hooks&lt;/strong&gt; and &lt;strong&gt;LocalStorage&lt;/strong&gt; and I'm writing about how I made it.&lt;/p&gt;

&lt;p&gt;I'm trying to be super detailed here (and also a lot of code comments 🤪) for anyone can easily follow the steps. However, all questions are welcome.&lt;/p&gt;

&lt;h1&gt;
  
  
  TL;DR
&lt;/h1&gt;

&lt;p&gt;Here is the &lt;strong&gt;Github&lt;/strong&gt; repository: &lt;a href="https://github.com/ducdev/todo-app-react-hooks-localstorage" rel="noopener noreferrer"&gt;https://github.com/ducdev/todo-app-react-hooks-localstorage&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Demo: &lt;a href="https://todo-app-react-hooks-localstorage.netlify.app/" rel="noopener noreferrer"&gt;https://todo-app-react-hooks-localstorage.netlify.app/&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  OK, let's start!
&lt;/h1&gt;

&lt;p&gt;We assume &lt;strong&gt;Node.js&lt;/strong&gt; and &lt;strong&gt;NPM&lt;/strong&gt; have been installed on your workspace.&lt;/p&gt;

&lt;p&gt;And now let's run this command to initialize a new &lt;strong&gt;React&lt;/strong&gt; project with &lt;strong&gt;Create React App&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app todo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flxfco3el4p6wg1ieateu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flxfco3el4p6wg1ieateu.gif" alt="npx create-react-app todo" width="833" height="579"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd todo
npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F23go4o71kwfe75ghpe0k.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F23go4o71kwfe75ghpe0k.gif" alt="cd todo" width="800" height="557"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For now, a default &lt;strong&gt;React&lt;/strong&gt; application is running at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:3000/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's open the created project's code and you will see &lt;code&gt;App.js&lt;/code&gt; in &lt;code&gt;src&lt;/code&gt; directory. We'll change the name of &lt;code&gt;App.js&lt;/code&gt; to &lt;code&gt;Todo.js&lt;/code&gt; and modify the code follow below code changes.&lt;/p&gt;

&lt;p&gt;Code changes:&lt;br&gt;
&lt;a href="https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/42ab20edd451ea87619cad15314c9afe995bcb6a" rel="noopener noreferrer"&gt;https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/42ab20edd451ea87619cad15314c9afe995bcb6a&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Save the files, and then you'll see the default &lt;strong&gt;React App&lt;/strong&gt; is now only a &lt;strong&gt;Todo&lt;/strong&gt; heading text is displayed.&lt;/p&gt;

&lt;p&gt;Next, we'll create &lt;code&gt;TodoList&lt;/code&gt; &amp;amp; &lt;code&gt;TodoItem&lt;/code&gt;, and then get them rendered with a mock array.&lt;/p&gt;

&lt;p&gt;Code changes:&lt;br&gt;
&lt;a href="https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/b002cb5772c5ff8262df706d3a54d06008875db5" rel="noopener noreferrer"&gt;https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/b002cb5772c5ff8262df706d3a54d06008875db5&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We got a fake &lt;strong&gt;Todo List&lt;/strong&gt; now 👏&lt;/p&gt;

&lt;p&gt;Now, we will create an input which allows us to add new &lt;strong&gt;Todo&lt;/strong&gt;. As mentioned above, I use browser's &lt;strong&gt;LocalStorage&lt;/strong&gt; to keep the &lt;strong&gt;Todo App&lt;/strong&gt;'s data, so the &lt;strong&gt;Todo List&lt;/strong&gt; won't get erased when we refresh browser window. &lt;/p&gt;

&lt;p&gt;We suppose to use &lt;code&gt;formik&lt;/code&gt; to create forms and validate form's values with &lt;code&gt;yup&lt;/code&gt;, so we need to run this command to add these packages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i formik yup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code changes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/f61da2a15cbbcd5929f01545800c94a3309974d6" rel="noopener noreferrer"&gt;https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/f61da2a15cbbcd5929f01545800c94a3309974d6&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8tdlp1pm8r4eez97ic87.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8tdlp1pm8r4eez97ic87.gif" alt="add todo" width="419" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically, now we have a form for adding new &lt;strong&gt;Todo&lt;/strong&gt;, then we'll create &lt;strong&gt;Remove&lt;/strong&gt; button for each &lt;strong&gt;Todo&lt;/strong&gt; item.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F85ykr3nbxrxv84lawv0x.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F85ykr3nbxrxv84lawv0x.gif" alt="remove todo" width="482" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code changes:&lt;br&gt;
&lt;a href="https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/57af5f2e5414709407345eef323cb97a59a76f8b" rel="noopener noreferrer"&gt;https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/57af5f2e5414709407345eef323cb97a59a76f8b&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We may want to mark a &lt;strong&gt;Todo&lt;/strong&gt; item as done or pending.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgr2ut8y0uraseslaoyqx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgr2ut8y0uraseslaoyqx.gif" alt="mark as done" width="531" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code changes:&lt;br&gt;
&lt;a href="https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/c3e90764641ffb16a80c5457f2f6714ef864e4b7" rel="noopener noreferrer"&gt;https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/c3e90764641ffb16a80c5457f2f6714ef864e4b7&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sometimes, we also need to edit the text of &lt;strong&gt;Todo&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3lwk4szz1kjk5lmq4bft.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3lwk4szz1kjk5lmq4bft.gif" alt="edit todo text" width="418" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code changes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/933eff9f3a5bcb0111032fbea5ba37b8d0dacae5" rel="noopener noreferrer"&gt;https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/933eff9f3a5bcb0111032fbea5ba37b8d0dacae5&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's time to add some styling, improvements and validations.&lt;br&gt;
We'll go with &lt;strong&gt;SASS&lt;/strong&gt; this time, it requires to add &lt;code&gt;node-sass&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i node-sass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fowm47x3l606pd975gk87.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fowm47x3l606pd975gk87.gif" alt="styling todo app" width="832" height="832"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code changes:&lt;br&gt;
&lt;a href="https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/d64447083a2ada0112c735d5329f59a1bd4cc9a4" rel="noopener noreferrer"&gt;https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/d64447083a2ada0112c735d5329f59a1bd4cc9a4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make sure the app is rendering properly, we don't forget adding tests. &lt;strong&gt;Create React App&lt;/strong&gt; uses &lt;strong&gt;React Testing Library&lt;/strong&gt; as selector for assertion. That's why we don't need to add anything else into the dependencies tree of the app.&lt;/p&gt;

&lt;p&gt;Code changes:&lt;br&gt;
&lt;a href="https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/c71edb6ef9b15396ea3ee6aed481bf7b3ad5b762" rel="noopener noreferrer"&gt;https://github.com/ducdev/todo-app-react-hooks-localstorage/commit/c71edb6ef9b15396ea3ee6aed481bf7b3ad5b762&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;To run the test&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, the app is now ready to be deployed and used, hope you enjoy the post. If you think there is something I can do better, leave a comment below ^_^&lt;/p&gt;

</description>
      <category>react</category>
      <category>localstorage</category>
      <category>todo</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Tell us your experience about poisonous work environment and how you moved on.</title>
      <dc:creator>Duc Le</dc:creator>
      <pubDate>Tue, 28 Aug 2018 09:15:15 +0000</pubDate>
      <link>https://forem.com/ducdev/tell-us-your-experience-about-poisonous-work-environment-and-how-you-moved-on-5h0a</link>
      <guid>https://forem.com/ducdev/tell-us-your-experience-about-poisonous-work-environment-and-how-you-moved-on-5h0a</guid>
      <description>&lt;p&gt;Dear fellow folks,&lt;/p&gt;

&lt;p&gt;Recently, I've seen many toxic comments on a recruitment website, someone shared their feedbacks about current or ex jobs. Those guys were hateful, disrespectful and angry, of course I know they have reasons for that while they're mostly mentioning about bias, bullying and blaming. I'm soon getting a new in-office job after years working remotely, I'm also afraid of these situations, changing work habitats may be a big challenge, I'm not sure how to deal with them TBH. I'd like to listen from your experiences and how you got these over.&lt;/p&gt;

&lt;p&gt;Best,&lt;/p&gt;

&lt;p&gt;Duc&lt;/p&gt;

</description>
      <category>environment</category>
      <category>personality</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
