Master ReactJS Part 5 MFurqan Riaz
Master ReactJS Part 5 MFurqan Riaz
Legal Notice:
Disclaimer Notice:
omissions, inaccuracies .
OceanofPDF.com
useLocation Hook in React | Complete React Course Article
#59
iNotebook: Fetching Notes from Context | Complete React
Course Article #60
Notebook: Adding NoteItem in a Separate Note component |
Complete React Course Article #61
Creating Notes Component
Creating NoteItem Component
Adding Card to NoteItems
Adding font awesome icons to iNotebook | Complete React
Course Article #62
Getting Started - Fontawesome
Adding Font Awesome icons to iNotebook
Showing an Alert Message
Creating Alert Component
Adding AddNote component to iNotebook | Complete React
Course Article #63
Creating New Functions
Add a Note Function
Creating an Add Note Component
Assigning Function
handleClick function
Creating onChange Function
Adding "delete note" functionality to iNotebook | Complete
React Course Article #64
Assigning the deleteNote Function
Creating a deleteNote Function
Adding "fetch notes" functionality to iNotebook | Complete
React Course Article #65
Creating an EditNote Function
Update Note API call
AddNote API call
CORS Express Package
Creating the Get Note Function
Using Get Notes Function
Adding a Modal for Editing Notes | Complete React Course
Article #66
Delete note API Call
Adding a Modal For Editing Notes
Creating an Update Note function
Adding the AddNote Form in the Modal
Enhancing the Edit Note Modal Form
Updating Notes on edit in the UI using React | Complete
React Course Article #67
Closing the Modal
Updating the Note
Fixing Errors
Updating the Note in the Frontend
Adding Frontend Validation + Few Fixes in iNotebook |
Complete React Course Article #68
No Notes to Display - Adding a Custom Message
Fixing Error - Unexpected Server Error
Enhancing the AddNote button
Fixing Issues - In NoteState.js
Enhancing the AddNote and UpdateNote form
OceanofPDF.com
useLocation Hook in React
| Complete React Course
Article #59
In the previous article, we have started working with the
context API in the iNotebook application. In this article, we
would be enhancing the iNotebook application and would be
learning about Location Hooks on the way and would be
learning about Location Hooks on the way. So, without
further ado let’s begin!
Getting Started
First of all, let’s refactor the code of NoteState.js and
noteContext.js files. IN the previous video, we have added a
state and an Update function to these files for the demo
purpose. Now, they are not required anymore so we can
remove the previous unnecessary code. We will be coming
on back to these files in the later articles.
Enhancing Navbar
We are changing the ‘‘title’’ and also the looks of the navbar
menu by adding a dark color to the Navbar. Make sure that
you have replaced the anchor tag with the link tag as we are
using react-router in this course.
OceanofPDF.com
Notebook: Adding
NoteItem in a Separate
Note component |
Complete React Course
Article #61
In the last article, we understood how to fetch all the notes
from the context. For that purpose, we have added some
sample Notes from the backend in the created context. In
this article, we will be creating a separate "Notes"
component, which will contain all the note items. Doing this
will help us to manage the iNotebook application
effortlessly. So, without further ado let’s begin!
Creating Notes Component
Firstly, we will create a new component named Notes.js.
Inside this component, we will add the ‘Your Notes’ section
from the Home.js file as shown below:
Figure 1.1: Creating Notes component
OceanofPDF.com
Adding font awesome
icons to iNotebook |
Complete React Course
Article #62
In the previous article, we have created NoteItem in a
Separate Note component. In addition to this, we have
rendered the Notes inside the specific Bootstrap cards. As we
have discussed, structuring the iNotebook application in that
way helps in the proper management of the app. In this
article, we will be adding font Awesome icons to iNotebook.
So, without further ado let’s begin!
Getting Started - Fontawesome
Font Awesome is a web font used by website designers &
developers for icons instead of traditional old image icons.
It’s flexible in terms of coloring, sizing & stacking on top of
other background styles using plain CSS. First of all, we have
to sign up to font awesome and then log in to the dashboard
with the help of our Email and password. After doing this, we
will copy the code of the font awesome kit, available in the
dashboard. Finally, we would add the font awesome kit code
to the index.html file, available under the Public folder.
Adding Font Awesome icons to
iNotebook
After performing the above step, we can use the icons from
the font awesome by simply searching and selecting the
icon. In the end, we have to just copy the code provided for
that icon by font awesome and paste it in the desired place.
In our case, we want the Delete and Edit icon to be displayed
in NoteItem, therefore we will add the code of both icons as
shown below:
OceanofPDF.com
Adding AddNote
component to iNotebook |
Complete React Course
Article #63
In the previous article, we saw how to add an alert and
different icons in the iNotebook application with the help of
Font awesome. In this article, we would be making the icons
functional to perform their specific task. So, without further
ado let’s learn how it’s done!
Creating New Functions
In NoteState, we would be creating some new functions to
add, edit and delete the note as shown below:
Add a Note Function
Let’s begin with creating a new function to add a note to the
application. So, let’s open the NoteState.js context and
begin creating it as shown below:
Figure 1.1: Add a Note Function
OceanofPDF.com
Adding "delete note"
functionality to iNotebook
| Complete React Course
Article #64
Earlier, we understood how to add the feature of adding a
new note to the iNotebook application. In today’s article, we
will be creating and assigning a delete note function to
remove the existing note of the client from the iNotebook
application. So, without further ado let’s begin:
Assigning the deleteNote Function
At this moment, we will be adding the feature of deleting
the existing Note from the iNotebook by clicking the delete
icon, available beside the ‘Title’ text of the Note. To do so,
we will add an Onclick listener to the delete icon, available
in NoteItems.js. Here’s how it is done:
Figure 1.1: Assigning the deleteNote function
OceanofPDF.com
Adding "fetch notes"
functionality to iNotebook
| Complete React Course
Article #65
In the previous article, we have added the functionality of
adding and deleting a Note from the frontend of the
iNotebook application. In today’s video, we will add the
functionality of Editing the note. In addition to this, we will
be adding the API calls to Add, Delete and edit the note in
the server-side of the iNotebook application. So, without
further ado let’s begin!
Creating an EditNote Function
First of all, we will create an Edit Note function in the
NoteState Context of the application. After that, we will be
able to use the EditNote function in different components.
Here’s how it is done:
OceanofPDF.com
Adding a Modal for Editing
Notes | Complete React
Course Article #66
In the previous article, we have added the functionality of
adding and updating a Note in the database of the
application with the help of API Calls. In today’s article, we
will be adding the functionality of deleting the note from the
database of the application. In addition to this we will add a
modal for editing the existing notes of the iNotebook
application. So, without further ado let’s begin!
Delete note API Call
In the previous article, we have made an AddNote, Fetching
all Note and Updating Note API call. In a similar manner, we
would be performing the deleteNote API call as shown
below. The only difference is that the Delete Note endpoint
URL is passed as the first parameter. Also, we are using the
delete method instead of ‘Get’ and ‘Post’ as shown below:
OceanofPDF.com
Updating Notes on edit in
the UI using React |
Complete React Course
Article #67
In the previous article, we have added the functionality of
deleting the note from the database of the application. In
addition to this, we have also seen how to add a Modal for
Editing the existing notes of the iNotebook application. In
today’s article, we will be updating the note in the frontend
of the application, with the closing of the Edit Note Modal.
So, without further ado let’s begin!
Closing the Modal
First of all, we will add an ID of the Note in the useState
hook, created in Notes.js. In addition to this, we would like
to set the ID as the current note ID while invoking the
"updateNote" function. Consequently, we would like to close
the modal after updating the note, that is after the
execution of the handle click function. To do that, we have
to add logic to click on the ‘close’ button. We can do so with
the help of the ‘Useref’ hook of React.
Figure 1.1: Closing the Modal
<button disabled={note.title.length<5 ||
note.description.length<5} type="submit"
className="btn btn-primary" onClick=
{handleClick}>Add Note</button>
Explanation: Here, we have added the disabled event
listener on the AddNote Button. This means that when the
length of the title or description is less than 5, then make
the AddNote button disabled. Remember to perform this
procedure in the Update note button of the Edit Note Modal.
Fixing Issues - In NoteState.js
If you remember, we have created a note function in our
NoteState context. Now, this note function is causing trouble
in the iNotebook application as we have provided a hard-
coded note in it. Instead of this, we need to pass the note,
which is returned by the JSON. Hence, we have updated the
function and thus our application is working magnificently.
Result: Hence, the new notes can be added and updated in
the iNotebook application without any errors.
Enhancing the AddNote and
UpdateNote form
We are facing a minor issue in the form, that is once the
note is added or updated in the iNotebook application then
the values are still shown in the fields. This isn’t an error,
but it destroys the user interface in our beloved application.
Therefore, we would like to empty all the fields after adding
or updating the note. Here’s how we can do that:
OceanofPDF.com