<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Shambashib's Blog]]></title><description><![CDATA[Hi! I am Shambashib Majumdar and I am cureently an Engineering student in CSE stream. I live in India and like developing things!]]></description><link>https://shambashibmajumdar.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 26 Jun 2026 12:46:36 GMT</lastBuildDate><atom:link href="https://shambashibmajumdar.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[A Pokémon themed Note Keeping Application using React!]]></title><description><![CDATA[Well! On writing my first technical blog, I am really feeling nostalgic about my childhood. The reason is simple. We all were at some point of our life obsessed with Pokemon! In my childhood, I and my friends used to coolly buy some chips and along w...]]></description><link>https://shambashibmajumdar.hashnode.dev/a-pokemon-themed-note-keeping-application-using-react</link><guid isPermaLink="true">https://shambashibmajumdar.hashnode.dev/a-pokemon-themed-note-keeping-application-using-react</guid><category><![CDATA[React]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[Shambashib Majumdar]]></dc:creator><pubDate>Fri, 03 Sep 2021 18:24:12 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1630684106037/3Jg-ZTX7_.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Well! On writing my <strong>first technical blog</strong>, I am really feeling nostalgic about my childhood. The reason is simple. We all were at some point of our life obsessed with Pokemon! In my childhood, I and my friends used to coolly buy some chips and along with it came our little world of joy! Yeah you guessed it right! </p>
<p>Pokémon themed merchandise were a craze, but at the same time, we used to be mad over buying Pokémon coins - more precisely TAZOS! </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630684930074/_vYNcJ26_.png" alt="Pokemon_Tazos.png" /></p>
<p>Now, I would like to suggest that you code along with me because it is best to type in the code yourself than to copy it because it builds up that muscle memory. When you're ready, let's get started - future React Master! 😉</p>
<p>All explanations for the project are in the code itself via the comments, but if you get stuck or want to view my CSS file, check it out on my GitHub repository:</p>
<p> <a target="_blank" href="https://github.com/shambashib20/PocketBook">My Git Repo</a></p>
<p>Want to test it before you make it? You can do that over here:</p>
<p> <a target="_blank" href="https://pocketbook-by-shambashib.herokuapp.com/">Project Demo</a></p>
<h2 id="pre-setup-installing-packages">Pre Setup - Installing Packages</h2>
<p>To complete this project exactly as (or however you want) I did, you will need to do the following in your preferred command line:</p>
<pre><code class="lang-nodejs">npx create-react-app note-keeper
npm i react-bootstrap bootstrap moment react-calander react-newline-to-break react-router-dom --save
</code></pre>
<p><strong>The packages (apart from bootstrap) that we just installed will help us do the following:</strong></p>
<ul>
<li><p><strong>react-newline-to-break:</strong> Converts your strings with newlines ("\n") to error/warning-free React components.</p>
</li>
<li><p><strong>moment:</strong> A JavaScript date library for parsing, validating, manipulating, and formatting dates.</p>
</li>
</ul>
<ul>
<li><p><strong>react-calander:</strong> Ultimate calendar for your React app.</p>
</li>
<li><p><strong>react-router-dom: </strong> DOM bindings for React Router.</p>
</li>
</ul>
<h1 id="step-1-intial-setup">Step 1 - Intial setup</h1>
<p>Set up your Index.js to contain the bootstrap modules that we will need for this project. Also, head over to FontAwesome and add your CND to your index.html header so that we can use the icons later on.</p>
<p><strong>For beginners: In my git repo, just navigate to my public folder and you can easily access the index.html file mentioned here! </strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> ReactDOM <span class="hljs-keyword">from</span> <span class="hljs-string">'react-dom'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'./index.css'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'bootstrap/dist/css/bootstrap.min.css'</span>;
<span class="hljs-keyword">import</span> App <span class="hljs-keyword">from</span> <span class="hljs-string">'./App'</span>;
<span class="hljs-keyword">import</span> reportWebVitals <span class="hljs-keyword">from</span> <span class="hljs-string">'./reportWebVitals'</span>;
ReactDOM.render(
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">React.StrictMode</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">App</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">React.StrictMode</span>&gt;</span></span>,
<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'root'</span>)
);
reportWebVitals();
</code></pre>
<p>This being said, you can edit your App.js file as follows and create a the following folders and files in your /src folder:</p>
<p><strong>Tips: Always try to build your components inside a different folder which can be christened as <em>components</em> and then build your components. This avoids the clutter in your workspace and also you can breathe more freely without getting irritated XD!</strong></p>
<p><strong>components (folder)</strong></p>
<ul>
<li>Calander.js (components file)</li>
<li>EditNotes.js (components file)</li>
<li>Favorites.js (components file)</li>
<li>ListNotes.js (components file)</li>
<li>NewNotes.js (components file)</li>
<li>Notes.js (components file)</li>
<li>ToDo.js (components file)</li>
</ul>
<p><strong>layout (folder)</strong></p>
<ul>
<li>Header.js (layout file)</li>
<li>Clips.js (layout file)</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-comment">//App.js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-comment">//our component files</span>
<span class="hljs-keyword">import</span> NotesApp <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/Notes'</span>;
<span class="hljs-keyword">import</span> Main <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/ToDo'</span>;
<span class="hljs-keyword">import</span> CalanderApp <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/Calander'</span>;
<span class="hljs-keyword">import</span> FavoriteLinks <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/Favorites'</span>;
<span class="hljs-keyword">import</span> Header <span class="hljs-keyword">from</span> <span class="hljs-string">'./layout/Header'</span>;
<span class="hljs-keyword">import</span> Clip <span class="hljs-keyword">from</span> <span class="hljs-string">'./layout/Clips'</span>;
<span class="hljs-comment">//Our Router components for DOM navigation</span>
<span class="hljs-keyword">import</span> { BrowserRouter, Route } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-router-dom'</span>;
<span class="hljs-comment">//Our React-Bootstrap Components</span>
<span class="hljs-keyword">import</span> {Container, Col, Row} <span class="hljs-keyword">from</span> <span class="hljs-string">'react-bootstrap'</span>;

<span class="hljs-comment">//main App component</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Container</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Row</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">header</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App-header"</span>&gt;</span>
              //will show our clip image (optional add-in)
              <span class="hljs-tag">&lt;<span class="hljs-name">Clip</span> /&gt;</span> 
          <span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">header</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App-header"</span>&gt;</span>
              //will show our page title
              <span class="hljs-tag">&lt;<span class="hljs-name">Header</span> /&gt;</span> 
          <span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Row</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Row</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-12 col-md-6 col-lg-6"</span>&gt;</span> 
              //will show our notes section
              <span class="hljs-tag">&lt;<span class="hljs-name">BrowserRouter</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"/"</span> <span class="hljs-attr">component</span>=<span class="hljs-string">{NotesApp}/</span>&gt;</span> 
              <span class="hljs-tag">&lt;/<span class="hljs-name">BrowserRouter</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-12 col-md-6 col-lg-6"</span>&gt;</span>  
              //will show our to-do section              
              <span class="hljs-tag">&lt;<span class="hljs-name">BrowserRouter</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"/"</span> <span class="hljs-attr">component</span>=<span class="hljs-string">{Main}/</span>&gt;</span> 
              <span class="hljs-tag">&lt;/<span class="hljs-name">BrowserRouter</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Row</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Row</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-12 col-md-6 col-lg-6"</span>&gt;</span> 
            //will show our favorites section
            <span class="hljs-tag">&lt;<span class="hljs-name">BrowserRouter</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"/"</span> <span class="hljs-attr">component</span>=<span class="hljs-string">{FavoriteLinks}/</span>&gt;</span> 
            <span class="hljs-tag">&lt;/<span class="hljs-name">BrowserRouter</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-12 col-md-6 col-lg-6"</span>&gt;</span> 
            //will show our calender section
            <span class="hljs-tag">&lt;<span class="hljs-name">BrowserRouter</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">CalendarApp</span> /&gt;</span>  
            <span class="hljs-tag">&lt;/<span class="hljs-name">BrowserRouter</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Row</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">Container</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-comment">//exports the App component to be used in index.js</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre>
<h1 id="step-2-layout-files">Step 2 - Layout files</h1>
<p>For this section, we will create our least-important files for the project just to get it out of the way. These are just UI components, so it's best to do it first (at least for me) so that we can focus on the functionality of our project more. Don't forget to  <a target="_blank" href="https://github.com/shambashib20/PocketBook/blob/master/src/index.css">copy my css code</a> and the  <a target="_blank" href="https://github.com/shambashib20/PocketBook/tree/master/src/css/fonts">custom fonts</a> needed for the project from my GitHub so that you don't get errors upon compilation (otherwise just add your own styling or remove it)! So, to the Header.js file, make the following changes:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//Header.js </span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> {Container, Row} <span class="hljs-keyword">from</span> <span class="hljs-string">'react-bootstrap'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Header</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Container</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Row</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"Header"</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"app-title"</span>&gt;</span>
                        //copy the .pixels CSS from my github
                        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'pixels'</span>&gt;</span> pxn <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
                        Poket Book
                        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'pixels'</span>&gt;</span> cli <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>           
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">Row</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Container</span>&gt;</span></span>
    );
  }

<span class="hljs-comment">//Exports Header Component to be used in app.js</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Header;
</code></pre>
<p>And then make the following changes to your Clips.js and save:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//Clips.js (optional)</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> {Container, Row} <span class="hljs-keyword">from</span> <span class="hljs-string">'react-bootstrap'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Clips</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Container</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Row</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"clip"</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"clip"</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"css/images/clip.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">img</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>      
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">Row</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Container</span>&gt;</span></span>
    );
  }

<span class="hljs-comment">//Exports Header Component to be used in app.js</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Clips;
</code></pre>
<h1 id="step-3-notes-section">Step 3 - Notes section</h1>
<p>To get started with our notes section, we will need to first make the following changes to our ListNotes.js so that we can list the notes that we will display on our main Notes.js component as we go.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//ListNotes.js </span>
<span class="hljs-keyword">import</span> React, {Component} <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> {NavLink} <span class="hljs-keyword">from</span> <span class="hljs-string">'react-router-dom'</span>;
<span class="hljs-keyword">import</span> moment <span class="hljs-keyword">from</span> <span class="hljs-string">'moment'</span>;
<span class="hljs-comment">//moment is a JavaScript date library for parsing, validating, manipulating, and formatting dates. </span>

<span class="hljs-comment">//we use a class component because our notes will consits of states and inheritance from a parent component which will pass properties down the functional component via props.</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ListNotes</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span> </span>{
    <span class="hljs-comment">//will render date to be displayed of note that was last added/edited</span>
    renderFormattedDate(date){
        <span class="hljs-keyword">return</span> moment(date).format(<span class="hljs-string">'DD MMM YYYY'</span>);
    }
    render() {
        <span class="hljs-comment">//if there are no notes to list, we will display a div with a message</span>
        <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.props.notes || <span class="hljs-built_in">this</span>.props.notes.length === <span class="hljs-number">0</span>) {
            <span class="hljs-keyword">return</span> (<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"no-notes"</span>&gt;</span>Oops! It seems that you have no notes. Try adding one? 😊<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>)
        }
        <span class="hljs-comment">//if there are notes to list, we will display a div with the notes</span>
        <span class="hljs-keyword">const</span> listItems = <span class="hljs-built_in">this</span>.props.notes.map(<span class="hljs-function">(<span class="hljs-params">note</span>) =&gt;</span>
                <span class="hljs-comment">//nav link to the div of respective note without displaying the id</span>
                <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">NavLink</span> <span class="hljs-attr">activeClassName</span>=<span class="hljs-string">'active'</span> <span class="hljs-attr">to</span>=<span class="hljs-string">{</span>`/<span class="hljs-attr">note</span>/${<span class="hljs-attr">note.id</span>}`}
                      <span class="hljs-attr">className</span>=<span class="hljs-string">"list-group-item"</span>
                      <span class="hljs-attr">key</span>=<span class="hljs-string">{note.id.toString()}</span>
                      <span class="hljs-attr">onClick</span>=<span class="hljs-string">{this.props.viewNote.bind(this,</span> <span class="hljs-attr">note.id</span>)}&gt;</span>
                    {/*Show note title*/}
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-truncate primary"</span>&gt;</span>{note.title}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    {/*Show note date*/}
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"font-weight-light font-italic small"</span>&gt;</span>{this.renderFormattedDate(note.date)}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">NavLink</span> &gt;</span>
        );
        //Displays the notes as a list
        return (<span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"list-group"</span>&gt;</span>{listItems}<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>);
    }
}

//exports for use in other files
export default ListNotes;</span>
</code></pre>
<p>Then, to be able to add new notes to our Notes.js component, we will need to do the following:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//NewNotes.js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { Redirect } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-router'</span>;
<span class="hljs-comment">//React Router is a collection of navigational components. </span>

<span class="hljs-comment">//this will hide our note id div from showing on the note screen</span>
<span class="hljs-keyword">const</span> divStyle = {
    <span class="hljs-attr">display</span>: <span class="hljs-string">'none'</span>
};

<span class="hljs-comment">//we use a class component because our notes will consits of states and inheritance from a parent component which will pass properties down the functional component via props.</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">NewNotes</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>{

        <span class="hljs-comment">//We use a constructor to set the initial state of the class object</span>
        <span class="hljs-keyword">constructor</span>(props) {
        <span class="hljs-built_in">super</span>(props);
        <span class="hljs-comment">//we set the initial state of the note nav to false, ie. there will be no notes to show thus no notes to "redirect" to when clicked</span>
        <span class="hljs-built_in">this</span>.state = {
            <span class="hljs-attr">redirect</span>: <span class="hljs-literal">false</span>
        };
        <span class="hljs-comment">//we bind the components to our event handlers to be executed</span>
        <span class="hljs-built_in">this</span>.saveNote = <span class="hljs-built_in">this</span>.saveNote.bind(<span class="hljs-built_in">this</span>);
        <span class="hljs-built_in">this</span>.deleteNote = <span class="hljs-built_in">this</span>.deleteNote.bind(<span class="hljs-built_in">this</span>);
    }

    <span class="hljs-comment">//saveNote Event Handler which will save a new note</span>
    saveNote(event) {
        <span class="hljs-comment">//the preventDefault() option is added to stop the page from reloading upon submitting a note</span>
        event.preventDefault();
        <span class="hljs-comment">//if the Title of the note is empty, we validate it via alert</span>
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.title.value === <span class="hljs-string">""</span>) {
            alert(<span class="hljs-string">"Title is needed"</span>);
        } <span class="hljs-keyword">else</span> {
             <span class="hljs-comment">//we assign each note with an id, title, desc and image upon submit</span>
            <span class="hljs-keyword">const</span> note = {
                <span class="hljs-attr">id</span>: <span class="hljs-built_in">Number</span>(<span class="hljs-built_in">this</span>.id.value),
                <span class="hljs-attr">title</span>: <span class="hljs-built_in">this</span>.title.value,
                <span class="hljs-attr">description</span>: <span class="hljs-built_in">this</span>.description.value
            }
             <span class="hljs-comment">//we set the new state of the note nav to true so that it can "redirect" to the note when clicked</span>
            <span class="hljs-built_in">this</span>.props.persistNote(note);
            <span class="hljs-built_in">this</span>.setState({
                <span class="hljs-attr">redirect</span>: <span class="hljs-literal">true</span>
            });
        }
    }

    <span class="hljs-comment">//deleteNote Event Handler which will delete(cancel the addition) a new note</span>
    deleteNote(event) {
        <span class="hljs-comment">//testing purposes only</span>
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'deleteNote'</span>);
        <span class="hljs-comment">//the preventDefault() option is added to stop the page from reloading upon submitting a note</span>
        event.preventDefault();
        <span class="hljs-comment">//we remove the note by deleting the respective id (note key)</span>
        <span class="hljs-built_in">this</span>.props.deleteNote(<span class="hljs-built_in">this</span>.props.note.id);
    }

    <span class="hljs-comment">//Switch between and then render(show) note titles, ie. either add a note or edit an exisitng note title.</span>
    renderFormTitleAction() {
        <span class="hljs-keyword">return</span> (<span class="hljs-built_in">this</span>.props.note.id !== <span class="hljs-literal">undefined</span>) ? <span class="hljs-string">"Edit Note"</span> : <span class="hljs-string">"New Note"</span>;
    }

    <span class="hljs-comment">//Render(show) save/delete note buttons for a new or existing note.</span>
    renderFormButtons() {
        <span class="hljs-comment">//if the note.id exists, then we can either delete or edit that note</span>
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.props.note.id !== <span class="hljs-literal">undefined</span>) {
            <span class="hljs-keyword">return</span> (<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
                { /* Show the save button to edit note */}
                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"btn btn-success float-right"</span>&gt;</span>Add Note<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
                { /* Show the delete button to delete note */}
                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{this.deleteNote}</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"btn btn-danger"</span>&gt;</span>Delete Note<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>);
        }
        <span class="hljs-keyword">return</span> (
            <span class="hljs-comment">/* Show the add button to save a new note */</span>
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"btn btn-success float-right"</span>&gt;</span>Add Note<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
        );
    }

    render() {

        <span class="hljs-comment">//existing note redirection</span>
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.state.redirect) {
            <span class="hljs-comment">//if the note doesn't exist, we return to main "/"</span>
            <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.props.note) {
                <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Redirect</span> <span class="hljs-attr">push</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/"</span>/&gt;</span></span>;
            }
            <span class="hljs-comment">//route to an existing note upon redirect, ie. note id: 1 will redirect to http://localhost:3000/note/1</span>
            <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Redirect</span> <span class="hljs-attr">push</span> <span class="hljs-attr">to</span>=<span class="hljs-string">{</span>`/<span class="hljs-attr">note</span>/${<span class="hljs-attr">this.props.note.id</span>}`}/&gt;</span></span>;
        }

        <span class="hljs-keyword">return</span> (
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-header"</span>&gt;</span>
                    {/* This will render the correct titles depending on if there are existing notes or not*/}
                    {this.renderFormTitleAction()}
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-body"</span>&gt;</span>
                    {/* Form that allows us to add a new note*/}
                    <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">"NewNotes"</span> <span class="hljs-attr">onSubmit</span>=<span class="hljs-string">{this.saveNote}</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"form-group"</span>&gt;</span>
                            {/* Renders a new note id (divStyle will hide this from view)*/}
                            <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"note_id"</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{divStyle}</span> <span class="hljs-attr">disabled</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">{id</span> =&gt;</span> this.id = id} defaultValue={this.props.note.id}/&gt;
                            <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                            {/* Renders a new note title */}
                            <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"note_title"</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"noteTitle"</span>&gt;</span>Title<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">{title</span> =&gt;</span> this.title = title} defaultValue={this.props.note.title} placeholder="Save Princess Peach"/&gt;
                            <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                            {/* Renders a new note description*/}
                            <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"note_desc"</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"noteDescTitle"</span>&gt;</span>Description<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">textarea</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">rows</span>=<span class="hljs-string">"10"</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">{description</span> =&gt;</span> this.description = description} defaultValue={this.props.note.description} placeholder="When Mario reaches the end of the course, remember to save Princess Peach or Luigi will! "/&gt;
                            <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                        {/* This will render the correct buttons depending on if there are existing notes or not*/}
                        {this.renderFormButtons()}
                    <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        )
    }
}

<span class="hljs-comment">//exports for use in other files</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> NewNotes;
</code></pre>
<p>Next up is the option to edit pre-added or new notes on our main Notes.js component.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//EditNotes.js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { Redirect } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-router'</span>;
<span class="hljs-keyword">import</span> moment <span class="hljs-keyword">from</span> <span class="hljs-string">'moment'</span>;
<span class="hljs-keyword">import</span> newline <span class="hljs-keyword">from</span> <span class="hljs-string">'react-newline-to-break'</span>;
<span class="hljs-comment">//moment is a JavaScript date library for parsing, validating, manipulating, and formatting dates. </span>

<span class="hljs-comment">//class component will switch between editing and deleting note rendering states</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EditNotes</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>{
    <span class="hljs-comment">//We use a constructor to set the initial state of the class object</span>
        <span class="hljs-keyword">constructor</span>(props) {
        <span class="hljs-built_in">super</span>(props);
        <span class="hljs-comment">//we set the initial state of the note nav to false, ie. there will be no notes to show thus no notes to "redirect" to when clicked</span>
        <span class="hljs-built_in">this</span>.state = { 
            <span class="hljs-attr">redirect</span> : <span class="hljs-literal">false</span>
        };
        <span class="hljs-comment">//we bind the components to our event handlers to be executed</span>
        <span class="hljs-built_in">this</span>.deleteNote = <span class="hljs-built_in">this</span>.deleteNote.bind(<span class="hljs-built_in">this</span>);
        <span class="hljs-built_in">this</span>.editNote = <span class="hljs-built_in">this</span>.editNote.bind(<span class="hljs-built_in">this</span>);
    }

    <span class="hljs-comment">//deleteNote Event Handler which will delete an existing note</span>
    deleteNote(event){
        <span class="hljs-comment">//the preventDefault() option is added to stop the page from reloading upon submitting a note</span>
        event.preventDefault();
        <span class="hljs-comment">//we remove the note by deleting the respective id (note key)</span>
        <span class="hljs-built_in">this</span>.props.deleteNote(<span class="hljs-built_in">this</span>.props.note.id);
    }

    <span class="hljs-comment">//editNote Event Handler which will update an existing note</span>
    editNote(event){
        <span class="hljs-comment">//the preventDefault() option is added to stop the page from reloading upon submitting a note</span>
        event.preventDefault();
        <span class="hljs-comment">//we edit the note by updating the respective id (note key)</span>
        <span class="hljs-built_in">this</span>.props.editNote(<span class="hljs-built_in">this</span>.props.note.id);
    }

    <span class="hljs-comment">//will render to be displayed when a new date whenever a note is edited</span>
    renderFormattedDate(){
        <span class="hljs-keyword">return</span> <span class="hljs-string">'Last edited:'</span> + moment(<span class="hljs-built_in">this</span>.props.note.date).format(<span class="hljs-string">"DD MMM YYYY [at] HH:mm"</span>);
    }

    render() {
        <span class="hljs-comment">//if the note doesn't exist, we return to main "/"</span>
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.state.redirect || !<span class="hljs-built_in">this</span>.props.note) {
            <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Redirect</span> <span class="hljs-attr">push</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/"</span>/&gt;</span></span>;
        }

        <span class="hljs-comment">//else we return a card with the note details</span>
        <span class="hljs-keyword">return</span> (
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card"</span>&gt;</span>
                {/*Will render the note title*/}
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-header"</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">h4</span>&gt;</span>{this.props.note.title}<span class="hljs-tag">&lt;/<span class="hljs-name">h4</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-body"</span>&gt;</span>
                    {/*Will render the note added/last updated date*/}
                    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-center font-weight-light small text-muted"</span>&gt;</span>{this.renderFormattedDate()}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                    {/*Will render the note description*/}
                    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-text-main"</span>&gt;</span>Title: {newline(this.props.note.title)}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-text"</span>&gt;</span>{newline(this.props.note.description)}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                    {/*Will render the delete button*/}
                    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{this.deleteNote}</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"btn btn-danger"</span>&gt;</span>Delete<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
                    {/*Will render the edit button*/}
                    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{this.editNote}</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"btn btn-success float-right"</span>&gt;</span>Edit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        )
    }
}

<span class="hljs-comment">//exports it for use in other files</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> EditNotes;
</code></pre>
<p>Now that we have created our components that will allow us to Add, Edit and List our notes, we can update our main Notes.js component as follows. While we're at it, we will also add the functionality to view and delete notes according to their note id.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//Notes.js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> moment <span class="hljs-keyword">from</span> <span class="hljs-string">'moment'</span>;
<span class="hljs-keyword">import</span> NewNotes <span class="hljs-keyword">from</span> <span class="hljs-string">'./NewNotes'</span>;
<span class="hljs-keyword">import</span> EditNotes <span class="hljs-keyword">from</span> <span class="hljs-string">'./EditNotes'</span>;
<span class="hljs-keyword">import</span> NotesList <span class="hljs-keyword">from</span> <span class="hljs-string">'./ListNotes'</span>;
<span class="hljs-keyword">import</span> { Route, Link } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-router-dom'</span>;

<span class="hljs-comment">//class component will switch between displaying all existing or new note rendering states</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">NotesApp</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>{
        <span class="hljs-comment">//We use a constructor to set the initial state of the class object</span>
        <span class="hljs-keyword">constructor</span>(props) {
        <span class="hljs-built_in">super</span>(props);
        <span class="hljs-comment">//will store the notes on our localStorage for storing user notes (local testing purposes)</span>
        <span class="hljs-keyword">const</span> notes = <span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">'notes'</span>) ? <span class="hljs-built_in">JSON</span>.parse(<span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">'notes'</span>)) : [];
        <span class="hljs-comment">//sets the initial state of all notes on storage base</span>
        <span class="hljs-built_in">this</span>.state = {
            <span class="hljs-attr">notes</span>: notes,
            <span class="hljs-attr">selectedNote</span>: <span class="hljs-literal">null</span>,
            <span class="hljs-attr">editMode</span>: <span class="hljs-literal">false</span>
        };
        <span class="hljs-comment">//we bind the components to our event handlers to be executed</span>
        <span class="hljs-built_in">this</span>.getNotesNextId = <span class="hljs-built_in">this</span>.getNotesNextId.bind(<span class="hljs-built_in">this</span>);
        <span class="hljs-built_in">this</span>.addNote = <span class="hljs-built_in">this</span>.addNote.bind(<span class="hljs-built_in">this</span>);
        <span class="hljs-built_in">this</span>.viewNote = <span class="hljs-built_in">this</span>.viewNote.bind(<span class="hljs-built_in">this</span>);
        <span class="hljs-built_in">this</span>.openEditNote = <span class="hljs-built_in">this</span>.openEditNote.bind(<span class="hljs-built_in">this</span>);
        <span class="hljs-built_in">this</span>.saveEditedNote = <span class="hljs-built_in">this</span>.saveEditedNote.bind(<span class="hljs-built_in">this</span>);
        <span class="hljs-built_in">this</span>.deleteNote = <span class="hljs-built_in">this</span>.deleteNote.bind(<span class="hljs-built_in">this</span>);
    }

    <span class="hljs-comment">//Initiates the note id's that are/will be stored via the localStorage </span>
    getNotesNextId() {
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.state.notes.length &gt; <span class="hljs-number">0</span> ? <span class="hljs-built_in">this</span>.state.notes[<span class="hljs-built_in">this</span>.state.notes.length - <span class="hljs-number">1</span>].id + <span class="hljs-number">1</span> : <span class="hljs-number">0</span>;
    }

    <span class="hljs-comment">//we persist the fetched data as string because we get the stored value parsed as a boolean, ie. does it have notes (yes/no)</span>
    persistNotes(notes) {
        <span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">'notes'</span>, <span class="hljs-built_in">JSON</span>.stringify(notes));
        <span class="hljs-built_in">this</span>.setState({<span class="hljs-attr">notes</span>: notes});
    }

    <span class="hljs-comment">//we give each note an id, date and new persisted state when we add a new note and push it to the notes local array.</span>
    addNote(note) {
        <span class="hljs-comment">//set notes values</span>
        note.id = <span class="hljs-built_in">this</span>.getNotesNextId();
        note.date = moment();
        <span class="hljs-keyword">const</span> notes = <span class="hljs-built_in">this</span>.state.notes;
        <span class="hljs-comment">//adds new note values</span>
        notes.push(note);
        <span class="hljs-built_in">this</span>.persistNotes(notes);
        <span class="hljs-built_in">this</span>.setState({<span class="hljs-attr">selectedNote</span>: <span class="hljs-literal">null</span>, <span class="hljs-attr">editMode</span>: <span class="hljs-literal">false</span>});
    }

    <span class="hljs-comment">//we view each note via mapping over it's id array, and when it is not found we handle it via an arror handler</span>
    viewNote(id) {
        <span class="hljs-keyword">const</span> notePosition = <span class="hljs-built_in">this</span>.state.notes.findIndex(<span class="hljs-function">(<span class="hljs-params">n</span>) =&gt;</span> n.id === id);
        <span class="hljs-comment">//display the note on the screen</span>
        <span class="hljs-keyword">if</span> (notePosition &gt;= <span class="hljs-number">0</span>) {
            <span class="hljs-built_in">this</span>.setState({
                <span class="hljs-attr">selectedNote</span>: <span class="hljs-built_in">this</span>.state.notes[notePosition], 
                <span class="hljs-attr">editMode</span>: <span class="hljs-literal">false</span>
            });
        } 
        <span class="hljs-comment">//error handler</span>
        <span class="hljs-keyword">else</span> {
            <span class="hljs-built_in">console</span>.warn(<span class="hljs-string">'The note with the id '</span> + id + <span class="hljs-string">' was not found. Please try again.'</span>);
        }
    }

    <span class="hljs-comment">//we edit each note via mapping over it's id array, and when it is not found we handle it via an arror handler</span>
    openEditNote(id) {
        <span class="hljs-keyword">const</span> notePosition = <span class="hljs-built_in">this</span>.state.notes.findIndex(<span class="hljs-function">(<span class="hljs-params">n</span>) =&gt;</span> n.id === id);
        <span class="hljs-comment">//displays the note to edit on screen</span>
        <span class="hljs-keyword">if</span> (notePosition &gt;= <span class="hljs-number">0</span>) {
            <span class="hljs-built_in">this</span>.setState({
                <span class="hljs-attr">selectedNote</span>: <span class="hljs-built_in">this</span>.state.notes[notePosition], 
                <span class="hljs-attr">editMode</span>: <span class="hljs-literal">true</span>
            });
        } 
        <span class="hljs-comment">//error handler</span>
        <span class="hljs-keyword">else</span> {
            <span class="hljs-built_in">console</span>.warn(<span class="hljs-string">'The note with the id '</span> + id + <span class="hljs-string">' was not found. Please try again.'</span>);
        }
    }

    <span class="hljs-comment">//we save each note via mapping over it's id array, and when it is not found we handle it via an arror handler</span>
    saveEditedNote(note) {
        <span class="hljs-keyword">const</span> notes = <span class="hljs-built_in">this</span>.state.notes;
        <span class="hljs-keyword">const</span> notePosition = notes.findIndex(<span class="hljs-function">(<span class="hljs-params">n</span>)=&gt;</span> n.id === note.id);
        <span class="hljs-comment">//displays the note to add on screen</span>
        <span class="hljs-keyword">if</span> (notePosition &gt;= <span class="hljs-number">0</span>) {
            note.date = moment();
            notes[notePosition] = note;
            <span class="hljs-built_in">this</span>.persistNotes(notes);
        } 
        <span class="hljs-comment">//error handler</span>
        <span class="hljs-keyword">else</span> {
            <span class="hljs-built_in">console</span>.warn(<span class="hljs-string">'The note with the id '</span> + note.id + <span class="hljs-string">' was not found. Please try again.'</span>);
        }
        <span class="hljs-comment">//updates notes to list</span>
        <span class="hljs-built_in">this</span>.setState({
            <span class="hljs-attr">selectedNote</span>: note, 
            <span class="hljs-attr">editMode</span>: <span class="hljs-literal">false</span>
        });
    }

    <span class="hljs-comment">//we delete each note via mapping over it's id array, and when it is not found we handle it via an arror handler</span>
    deleteNote(id) {
        <span class="hljs-keyword">const</span> notes = <span class="hljs-built_in">this</span>.state.notes;
        <span class="hljs-keyword">const</span> notePosition = notes.findIndex(<span class="hljs-function">(<span class="hljs-params">n</span>)=&gt;</span> n.id === id);
        <span class="hljs-comment">//deletes the note from the screen screen</span>
        <span class="hljs-keyword">if</span> (notePosition &gt;= <span class="hljs-number">0</span>) {
            <span class="hljs-keyword">if</span> (<span class="hljs-built_in">window</span>.confirm(<span class="hljs-string">'Are you sure you want to delete this note?'</span>)) {
                notes.splice(notePosition, <span class="hljs-number">1</span>);
                <span class="hljs-built_in">this</span>.persistNotes(notes);
                <span class="hljs-built_in">this</span>.setState({<span class="hljs-attr">selectedNote</span>: <span class="hljs-literal">null</span>, <span class="hljs-attr">editMode</span>: <span class="hljs-literal">false</span>});
            }
        } 
        <span class="hljs-comment">//error handler</span>
        <span class="hljs-keyword">else</span> {
            <span class="hljs-built_in">console</span>.warn(<span class="hljs-string">'The note with the id '</span> + id + <span class="hljs-string">' was not found. Please try again.'</span>);
        }
    }

    <span class="hljs-comment">//initiates the values of each new note</span>
    getEmptyNote() {
        <span class="hljs-keyword">return</span> {
            <span class="hljs-attr">title</span>: <span class="hljs-string">""</span>,
            <span class="hljs-attr">description</span>: <span class="hljs-string">""</span>,
            <span class="hljs-attr">image</span>: <span class="hljs-string">""</span>
        };
    }

    <span class="hljs-comment">//renders the notes list menu on the screen</span>
    renderMenu () {
        <span class="hljs-keyword">return</span> (
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card"</span>&gt;</span>
                {this.renderHeader()}
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-body"</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">NotesList</span> <span class="hljs-attr">notes</span>=<span class="hljs-string">{this.state.notes}</span> <span class="hljs-attr">viewNote</span>=<span class="hljs-string">{this.viewNote}/</span>&gt;</span>   
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        )
    }

    <span class="hljs-comment">//renders the notes header on the screen</span>
    renderHeader() {
        <span class="hljs-keyword">return</span> (
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-header"</span>&gt;</span>
                {/*renders close view*/ }
                <span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">exact</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"/note"</span> <span class="hljs-attr">render</span>=<span class="hljs-string">{routeProps</span> =&gt;</span> 
                    <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/"</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"btn btn-danger"</span>&gt;</span>Cancel Note<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span> }/&gt;
                {/*renders note view*/ }
                {["/", "/note/:id"].map(path =&gt;
                <span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{path}</span> <span class="hljs-attr">exact</span> <span class="hljs-attr">path</span>=<span class="hljs-string">{path}</span> <span class="hljs-attr">render</span>=<span class="hljs-string">{routeProps</span> =&gt;</span> 
                    <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/note"</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"btn btn-success"</span>&gt;</span>New Note<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>}/&gt;
                )}
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        )
    }

    <span class="hljs-comment">//display the notes when clicked on for editing, note and empty note views</span>
    setMainAreaRoutes() {
        <span class="hljs-keyword">const</span> editMode = <span class="hljs-built_in">this</span>.state.editMode;
        <span class="hljs-keyword">return</span> (<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
            {/*edits either the new note or exisitn note*/ }
            {editMode ? (
                <span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">exact</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"/note/:id"</span>
                       <span class="hljs-attr">render</span>=<span class="hljs-string">{routeProps</span> =&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">NewNotes</span> <span class="hljs-attr">persistNote</span>=<span class="hljs-string">{this.saveEditedNote}</span> <span class="hljs-attr">deleteNote</span>=<span class="hljs-string">{this.deleteNote}</span> <span class="hljs-attr">note</span>=<span class="hljs-string">{this.state.selectedNote}/</span>&gt;</span>}
                    /&gt;
                ) : (
                <span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">exact</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"/note/:id"</span> <span class="hljs-attr">render</span>=<span class="hljs-string">{routeProps</span> =&gt;</span>     
                    <span class="hljs-tag">&lt;<span class="hljs-name">EditNotes</span> <span class="hljs-attr">editNote</span>=<span class="hljs-string">{this.openEditNote}</span> <span class="hljs-attr">deleteNote</span>=<span class="hljs-string">{this.deleteNote}</span> <span class="hljs-attr">note</span>=<span class="hljs-string">{this.state.selectedNote}/</span>&gt;</span>}
                /&gt;
            )}
            {/*displays if no notes can be found*/ }
            <span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">exact</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"/note"</span>
                   <span class="hljs-attr">render</span>=<span class="hljs-string">{routeProps</span> =&gt;</span>  <span class="hljs-tag">&lt;<span class="hljs-name">NewNotes</span> <span class="hljs-attr">persistNote</span>=<span class="hljs-string">{this.addNote}</span> <span class="hljs-attr">note</span>=<span class="hljs-string">{this.getEmptyNote()}/</span>&gt;</span>}
                /&gt;
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>)
    }

    render() {
        <span class="hljs-keyword">return</span> (
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"notesApp container-fluid"</span>&gt;</span>
                 <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-notes-header"</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span> NOTES <span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"row"</span>&gt;</span>
                    {/*renders note list menu*/ }
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-12"</span>&gt;</span>
                        {this.renderMenu()}  
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    {/*renders note area menu*/ }
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-12"</span>&gt;</span>
                        {this.setMainAreaRoutes()}
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        );
    }
}

<span class="hljs-comment">//exports for use in other files</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> NotesApp;
</code></pre>
<p>After completing all the steps above, <strong>recheck your work</strong> by comparing all your work with mine.</p>
<p>If you have done all those successfully, then something should come up on your screen like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630691758451/-8QaOA8aA.png" alt="Notes_Part.png" /></p>
<h1 id="step-4-to-do-section">Step 4 - To Do section</h1>
<p>Now that we've added our notes section, it is time to move on to our To-Do list. Now, in this component, we will be able to add new to-do-list items, mark them as complete, unmark them, and even delete them.</p>
<p><strong>As a small challenge, you can update this to also work with Local Storage as we did in the Notes.js section!</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">//ToDo.js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> {Col, Row} <span class="hljs-keyword">from</span> <span class="hljs-string">'react-bootstrap'</span>;

<span class="hljs-comment">//Initiate the ToDo function that will display our main display components, ie the list, check/uncheck button, and delete button</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Todo</span>(<span class="hljs-params">{ todo, index, completeTodo, unCompleteTodo, removeTodo }</span>) </span>{
    <span class="hljs-keyword">return</span> (
          <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>
            <span class="hljs-attr">className</span>=<span class="hljs-string">"todo"</span>
            <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">textDecoration:</span> <span class="hljs-attr">todo.isCompleted</span> ? "<span class="hljs-attr">line-through</span>" <span class="hljs-attr">:</span> "" }}
          &gt;</span>
          {todo.text}
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
          {/*completes list*/}
          <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> completeTodo(index)} className="btn btn-icon-check"&gt; 
            <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"fas fa-check-circle"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
          {/*uncompletes list*/}
          <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> unCompleteTodo(index)} className="btn btn-icon-redo"&gt; 
          <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"fas fa-redo"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
          {/*deletes list*/}
          <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> removeTodo(index)} className="btn btn-icon-trash"&gt; <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"fas fa-trash"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
  }

  <span class="hljs-comment">//sets our initial state of our todo list to null</span>
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">TodoForm</span>(<span class="hljs-params">{ addTodo }</span>) </span>{
    <span class="hljs-keyword">const</span> [value, setValue] = React.useState(<span class="hljs-string">""</span>);
    <span class="hljs-keyword">const</span> handleSubmit = <span class="hljs-function"><span class="hljs-params">e</span> =&gt;</span> {
      e.preventDefault();
      <span class="hljs-keyword">if</span> (!value) <span class="hljs-keyword">return</span>;
      addTodo(value);
      setValue(<span class="hljs-string">""</span>);
    };

    <span class="hljs-comment">//returns a form to add a new todo item to our list</span>
    <span class="hljs-keyword">return</span> (
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">onSubmit</span>=<span class="hljs-string">{handleSubmit}</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-header-todo mb-3"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Row</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-md-8"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">input</span> 
            <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span>
            <span class="hljs-attr">className</span>=<span class="hljs-string">"input"</span>
            <span class="hljs-attr">value</span>=<span class="hljs-string">{value}</span>
            <span class="hljs-attr">onChange</span>=<span class="hljs-string">{e</span> =&gt;</span> setValue(e.target.value)
            }/&gt;
           <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>
           <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-md-4 btn-add"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"btn-success"</span>&gt;</span>Add To-Do<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
           <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Row</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span></span>
    );
  }

  <span class="hljs-comment">//Main function ties it together</span>
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">//default values are passed for display purposes</span>
    <span class="hljs-keyword">const</span> [todos, setTodos] = React.useState([
      {
        <span class="hljs-attr">text</span>: <span class="hljs-string">"Do Some Magic With React 🔮"</span>,
        <span class="hljs-attr">isCompleted</span>: <span class="hljs-literal">false</span>
      },
      {
        <span class="hljs-attr">text</span>: <span class="hljs-string">"Ban Townies From Sims Game ❌"</span>,
        <span class="hljs-attr">isCompleted</span>: <span class="hljs-literal">false</span>
      },
      {
        <span class="hljs-attr">text</span>: <span class="hljs-string">"Water The Dead Cactus 🌵"</span>,
        <span class="hljs-attr">isCompleted</span>: <span class="hljs-literal">false</span>
      }
    ]);

    <span class="hljs-comment">//adds a todo to the list</span>
    <span class="hljs-keyword">const</span> addTodo = <span class="hljs-function"><span class="hljs-params">text</span> =&gt;</span> {
      <span class="hljs-keyword">const</span> newTodos = [...todos, { text }];
      setTodos(newTodos);
    };

    <span class="hljs-comment">//checks the complete button and strikes through the text</span>
    <span class="hljs-keyword">const</span> completeTodo = <span class="hljs-function"><span class="hljs-params">index</span> =&gt;</span> {
      <span class="hljs-keyword">const</span> newTodos = [...todos];
      newTodos[index].isCompleted = <span class="hljs-literal">true</span>;
      setTodos(newTodos);
    };

    <span class="hljs-comment">//checks the uncomplete button and unstrikes through the text</span>
    <span class="hljs-keyword">const</span> unCompleteTodo = <span class="hljs-function"><span class="hljs-params">index</span> =&gt;</span> {
      <span class="hljs-keyword">const</span> newTodos = [...todos];
      newTodos[index].isCompleted = <span class="hljs-literal">false</span>;
      setTodos(newTodos);
    };

    <span class="hljs-comment">//deletes the whole list item as a whole</span>
    <span class="hljs-keyword">const</span> removeTodo = <span class="hljs-function"><span class="hljs-params">index</span> =&gt;</span> {
      <span class="hljs-keyword">const</span> newTodos = [...todos];
      newTodos.splice(index, <span class="hljs-number">1</span>);
      setTodos(newTodos);
    };

    <span class="hljs-comment">//renders the main ui of to do list</span>
    <span class="hljs-keyword">return</span> (
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"todoList container-fluid"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"todo-header"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"todo-list-header"</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>TO-DO <span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>   
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card"</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-body todo-body"</span>&gt;</span>
                  {/*form to add a new to do item*/}
                  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-todo-form"</span>&gt;</span>
                      <span class="hljs-tag">&lt;<span class="hljs-name">TodoForm</span> <span class="hljs-attr">addTodo</span>=<span class="hljs-string">{addTodo}/</span>&gt;</span>
                  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-list"</span>&gt;</span>
                      {/*maps over todo items and instantiates functions for existing items*/}
                      {todos.map((todo, index) =&gt; (
                      <span class="hljs-tag">&lt;<span class="hljs-name">Todo</span>
                        <span class="hljs-attr">key</span>=<span class="hljs-string">{index}</span>
                        <span class="hljs-attr">index</span>=<span class="hljs-string">{index}</span>
                        <span class="hljs-attr">todo</span>=<span class="hljs-string">{todo}</span>
                        <span class="hljs-attr">completeTodo</span>=<span class="hljs-string">{completeTodo}</span>
                        <span class="hljs-attr">removeTodo</span>=<span class="hljs-string">{removeTodo}</span>
                        <span class="hljs-attr">unCompleteTodo</span>=<span class="hljs-string">{unCompleteTodo}</span>
                      /&gt;</span>
                    ))}   
                  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
              <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-pixels-todo"</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"pixels"</span>&gt;</span>todos<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
  }

  <span class="hljs-comment">//exports for use in other files</span>
  <span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Main;
</code></pre>
<p>You should get something like this before:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630692112258/E9cAeS6an.png" alt="Todo_Part.png" /></p>
<p>#Step 5 - Favorites section</p>
<p>Our favorites section functions extremely similar to our ToDo.js file, it just has the added extra of visiting our favorites. As an extra bonus challenge, you can update this to also work with Local Storage as we did in the Notes.js section!</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//Favorites.js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> {Col, Row} <span class="hljs-keyword">from</span> <span class="hljs-string">'react-bootstrap'</span>;

<span class="hljs-comment">//Initiate the Faves function that will display our main display components, ie the link, button, and category</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Faves</span> (<span class="hljs-params">{ favorite, visitFaves, index, removeFaves }</span>) </span>{
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Row</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"fave-link"</span>&gt;</span>
            {/*displays link*/}
            <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-8 favorites-p"</span>&gt;</span> 
                <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">{favorite.text}</span>&gt;</span>{favorite.text}<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>

            {/*deletes favorite*/}
            <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-4"</span>&gt;</span> 
                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> removeFaves(index)} className="btn btn-icon-trash"&gt; <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"fas fa-trash"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> visitFaves(index)} className="btn btn-icon-redo"&gt;<span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"fas fa-globe"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Row</span>&gt;</span></span>
    );
  }

    <span class="hljs-comment">//sets our initial state of our fave list to null</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">FaveForm</span>(<span class="hljs-params">{ addFaves }</span>) </span>{
    <span class="hljs-keyword">const</span> [value, setValue] = React.useState(<span class="hljs-string">""</span>);
    <span class="hljs-keyword">const</span> handleSubmit = <span class="hljs-function"><span class="hljs-params">e</span> =&gt;</span> {
      e.preventDefault();
      <span class="hljs-keyword">if</span> (!value) <span class="hljs-keyword">return</span>;
      addFaves(value);
      setValue(<span class="hljs-string">""</span>);
    };

    <span class="hljs-comment">//returns a form to add a new fave item to our list</span>
    <span class="hljs-keyword">return</span> (
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">onSubmit</span>=<span class="hljs-string">{handleSubmit}</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"mb-3"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Row</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-md-8 "</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">input</span> 
            <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span>
            <span class="hljs-attr">className</span>=<span class="hljs-string">"faves-input"</span>
            <span class="hljs-attr">value</span>=<span class="hljs-string">{value}</span>
            <span class="hljs-attr">onChange</span>=<span class="hljs-string">{e</span> =&gt;</span> setValue(e.target.value)
            }/&gt;
          <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-md-4"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"faves-input-btn"</span>&gt;</span>Favorite!💖<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Row</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span></span>
    );
  }

    <span class="hljs-comment">//FavoriteLinks function ties it together</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">FavoriteLinks</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> [favorites, setFaves] = React.useState([
    <span class="hljs-comment">//default values are passed for display purposes</span>
      {
        <span class="hljs-attr">text</span>: <span class="hljs-string">"https://www.youtube.com"</span>
      },
      {
        <span class="hljs-attr">text</span>: <span class="hljs-string">"https://github.com/christinec-dev"</span>
      },
      {
        <span class="hljs-attr">text</span>: <span class="hljs-string">"https://developer.mozilla.org/"</span>
      }
    ]);

    <span class="hljs-comment">//adds a favorite to the list</span>
    <span class="hljs-keyword">const</span> addFaves = <span class="hljs-function"><span class="hljs-params">text</span> =&gt;</span> {
      <span class="hljs-keyword">const</span> newFaves = [...favorites, { text}];
      setFaves(newFaves);
    };

    <span class="hljs-comment">//deletes the favorite from list</span>
    <span class="hljs-keyword">const</span> removeFaves = <span class="hljs-function"><span class="hljs-params">index</span> =&gt;</span> {
      <span class="hljs-keyword">const</span> newFaves = [...favorites];
      newFaves.splice(index, <span class="hljs-number">1</span>);
      setFaves(newFaves);
    };

    <span class="hljs-comment">//deletes the favorite from list</span>
    <span class="hljs-keyword">const</span> visitFaves = <span class="hljs-function"><span class="hljs-params">index</span> =&gt;</span> {
      <span class="hljs-keyword">const</span> newFaves = <span class="hljs-built_in">window</span>.location.href=<span class="hljs-string">`{favorite.text}`</span>;
      setFaves(newFaves);
    };

    <span class="hljs-comment">//renders the main ui of to do list</span>
    <span class="hljs-keyword">return</span> (
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"favorites mb-3 container-fluid"</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"favorites-header"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>FAVORITE SITES<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card-body favorites"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Row</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-md-8"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">h3</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"cat-header"</span>&gt;</span>Website<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span> 
            <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"col-md-4"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">h3</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"cat-header"</span>&gt;</span>Modify<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Row</span>&gt;</span>
        {/*maps over todo items and instantiates functions for existing items*/}
          {favorites.map((favorite, index, category) =&gt; (
            <span class="hljs-tag">&lt;<span class="hljs-name">Faves</span>
              <span class="hljs-attr">key</span>=<span class="hljs-string">{index}</span>
              <span class="hljs-attr">index</span>=<span class="hljs-string">{index}</span>
              <span class="hljs-attr">favorite</span>=<span class="hljs-string">{favorite}</span>
              <span class="hljs-attr">removeFaves</span>=<span class="hljs-string">{removeFaves}</span>
              <span class="hljs-attr">visitFaves</span>=<span class="hljs-string">{visitFaves}</span>
              <span class="hljs-attr">category</span>=<span class="hljs-string">{category}</span>  
            /&gt;</span>
          ))}
        {/*form to add a new item*/}
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"faves-form"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">FaveForm</span> <span class="hljs-attr">addFaves</span>=<span class="hljs-string">{addFaves}/</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
  }

<span class="hljs-comment">//exports for use in other files</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> FavoriteLinks;
</code></pre>
<p>You should get something like this</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630692391295/BlRkZRLIE.png" alt="Favorites_Part.png" /></p>
<h1 id="step-6-calendar-section">Step 6 - Calendar Section</h1>
<p>We're almost at the end, and what better way to wrap up our notes keeping app than to add a calander? Now for this, we use the calander npm package installed above to render our calander. It is a neat package because you can view the weeks, months, year(s), and even the decades without having to code anything!</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//Calender.js</span>
<span class="hljs-keyword">import</span> React, {useState} <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>
<span class="hljs-keyword">import</span> Calendar <span class="hljs-keyword">from</span> <span class="hljs-string">'react-calendar'</span>
<span class="hljs-keyword">import</span> <span class="hljs-string">'react-calendar/dist/Calendar.css'</span>;

<span class="hljs-comment">//calender that will be shown on our main page</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">CalenderApp</span> (<span class="hljs-params"></span>) </span>{
<span class="hljs-comment">//main date functions to initialize our date state</span>
<span class="hljs-keyword">const</span> [dateState, setDateState] = useState(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>())
<span class="hljs-comment">//changes date to current selection on calender</span>
<span class="hljs-keyword">const</span> changeDate = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
    setDateState(e)
}
<span class="hljs-keyword">return</span> (
    <span class="hljs-comment">//returns the calender as rendered cal</span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"container-fluid"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"favorites-header"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>CALENDER<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"calender-main"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"card"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"calender-card-body"</span>&gt;</span>
            <span class="hljs-tag">&lt;&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Calendar</span> 
            <span class="hljs-attr">value</span>=<span class="hljs-string">{dateState}</span>
            <span class="hljs-attr">onChange</span>=<span class="hljs-string">{changeDate}</span>
            <span class="hljs-attr">className</span>=<span class="hljs-string">"calender-body"</span>
            /&gt;</span>
          <span class="hljs-tag">&lt;/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  &lt;/div&gt;
  )
}
</code></pre>
<p>You should get this look when you get done with this part.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630692793737/1aNPAfIE9.png" alt="Calendar_Part.png" /></p>
<p>#Section 7 -  Wrapping up</p>
<p>Now that you have created all the components, and added the necessary CSS styling, it is time to test our application. I do this frequently during project creation to test my code, but during this tutorials we only test it at the end - however you want to do it, is up to you! Run your project with the following command:</p>
<pre><code class="lang-javascript">npm start
</code></pre>
<p>You should get something similar to this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630693004075/3MS2E56SR.png" alt="Final_Website.png" /></p>
<p>Atlast after a long work we are finally here! Our short journey of me guiding you through this project stops here partially! Why partially?? Because we have not yet deployed our site!</p>
<p>Do you want this project to be hosted ? Want my guidance on it?
Like this blog and comment below "Deployment Op" to make me release my deployment article for this one. Until then, goodbye and take care!</p>
]]></content:encoded></item></channel></rss>