Master ReactJS Part 6 MFurqan Riaz
Master ReactJS Part 6 MFurqan Riaz
Legal Notice:
Disclaimer Notice:
OceanofPDF.com
Adding Login Component to
iNotebook | Complete React
Course Article #69
In the earlier articles, we have seen how to add, update and
delete a Note from the Frontend as well as the backend of
the iNotebook application. Moreover, we have fixed some
major and minor issues in our iNotebook application. In
today’s article, we will be adding the Login and SignUp
functionality to maintain the privacy of the user in the
iNotebook application. So, without further ado let’s begin!
Adding the Login and SignUp Buttons
First of all, we would like to add a login and Sign Up section
to the Navbar of the application. To do that, we will add two
Bootstrap buttons in the Navbar component as shown
below:
OceanofPDF.com
Adding SignUp Component to
iNotebook | Complete React
Course Article #70
In the previous articles, we have fixed some major and
minor issues in our iNotebook application. Moreover, we
have created and added the login functionality for accessing
the Add Note page of the iNotebook application. In today’s
article, we will be creating and adding the signUp
component in the application. So, without further ado let’s
begin!
Adding a Sign-Up form
First of all, we will add and enhance our desired bootstrap
Form in the SignUp component. Here, we will be adding the
Name, Email, Password and Confirm Password field in our
SignUp form. Moreover, we have added an ‘Onchange’
function to the onChange event of the form as shown below:
OceanofPDF.com
Adding Alerts to Login,
Signup & Notes Component
of iNotebook | Complete
React Course Article #71
In the previous article, we have created the fully functional
Login and SignUp endpoint in the iNotebook application. In
today’s article, we will be adding a proper alert to the login,
SignUp and Notes Component of the iNotebook application.
In addition to this, we will also be adding the alert in the
different functions, such as DeleteNote, AddNote etc, of the
application. So, without further ado let’s begin!
Recall - Show Alert function
If you remember, we have created an Alert component for
our textUtils application. Now, we will use the same alert
component in the iNotebook application.
Adding the ShowAlert Function - In
app.js
First of all, we will add a ShowAlert function in App.js as
shown below. Remember, we are using the useState hook of
React to set the State of the Alert.
Figure 1.1: Adding the ShowAlert Function
deleteNote Function
Similarly, we will add the below piece of code to show an
alert message on the deletion of the Notes.
props.showAlert("Deleted successfully",
"success")
addNote function
Moreover, we would like to show an alert whenever a new
note is being added to the application. To do so, first of all,
we will pass the showAlert component to the AddNote.js. In
AddNote.js, we will add the below piece of code in the
handleClick function, which is responsible for adding the
Notes in the application.
OceanofPDF.com
Fetching User Specific Notes
in iNotebook | Complete
React Course Article #72
In the previous article, we have added Alerts to log in,
Signup & Notes Component of the iNotebook application. In
addition to this, we have also added the alert in the different
functions, such as DeleteNote, AddNote etc, of the
application. In today’s article, we will be fetching the User
Specific Notes in iNotebook. So, without further ado let’s
begin!
Getting Started
If you remember, we have hardcoded the authtoken in the
NoteState.js context. Now, instead of hardcoding, we will be
taking the authtoken from the Local Storage. To do so, we
will change all the occurrences of the authtoken in
NoteState context with the following piece of code:
"auth-token": localStorage.getItem('token')
OceanofPDF.com
Introduction to Redux |
Complete React Course
Article #73
In the previous article, we have fetched the user-specific
notes in the iNotebook application and have wrapped it up.
In today’s article, we will be having a short introduction to
Redux. Consequently, we will be understanding Redux with
the help of fascinating visuals and an analogy. So, without
further ado let’s begin!
Redux
It is a state management library for javascript applications.
We can use it with React, Angular,Vue.js and vanilla JS. This
is because it is a state management library, therefore it
doesn’t care about which library we are using to build the
UI.
The problem without a State
Management library
Well, if you have ever built an application with a complex UI,
you have probably come across a situation where you need
to keep different parts of the UI synced. In a complex
application, let’s say the user changes data in one part of
the application then other parts of the application should be
immediately updated to reflect the changes. In more
complex scenarios, the data also gets updated as a result of
network requests or background tasks. Therefore, we need
to write a lot of code to keep it synced.
Why Use Redux - State Management
Library?
With the help of Redux, instead of scattering the application
state in various components of the application, we will store
all the application state inside a central repository, that is a
single JS object called the Redux Store. You can assume it as
a kind of database for the front end of an application. So
with this architecture, the different components of the app
have to no longer maintain their own state. Instead, they
get what they need from the Redux store. Redux as an
architecture also makes it easy to understand how the data
changes in our application, if something goes wrong we can
see exactly how, why, when, and where the data changed.
Remember, Redux performs a similar function as Context
API and hence helps in reducing the prop drilling. Hence,
Redux is a custom solution for state management.
In a Nutshell - The Need to Use Redux
● Redux centralizes the application’s state
● It also makes the data flow transparent and predictable
● In addition to this, It also makes Testing very easy.
● It brings out Consistency throughout the application
Actions & Reducers
Actions: An action is a plain object that describes the
intention to cause change. Let’s suppose we are creating an
iNotebook application, which contains a lot of notes. Now,
suppose, we want to change the correspondence of the
notes with respect to their Users. To do so, we will bring an
action to change the Notes array by adding another note.
OceanofPDF.com
Setting up a React
Application for Redux |
Complete React Course
Article #74
In the previous article, we have a short introduction to
Redux. Consequently, we have understood Redux with the
help of fascinating visuals and an analogy. In today’s article,
we will be setting up an application that will help us to
understand Redux efficiently. So, without further ado let’s
begin!
Creating a React App
First of all, we will create a new folder named the Redux app
inside the React Course folder. After that, we will open the
folder in vs code and use the below command to create the
React app:
npx create-react-app .
Adding Bootstrap
After creating the application, we will add some bootstrap
code in the application for the enhancement of the
application. Here, we have created Navbar.js and have
added the Navbar component of the bootstrap. Remember,
to import and use the Navbar component in the app.js.
Hence, the Navbar will be added to the application!
Getting Started - State Bank of Harry
application
For understanding Redux, we are going to create a simple
simulation of a Banking application. In the application, we
will add the functionality of incrementing and decrementing
the amount of money available in the bank.
Adding the 'Your Balance' Button
Firstly, we will add a "Your Balance" button in the Navbar
section of the application. You can add the button by using
the below piece of code:
OceanofPDF.com
Creating a Reducer & Action
Creator in Redux | Complete
React Course Article #75
In the previous article, we have set up a Basic React
Application to help us understand Redux. Moreover, we have
added a bank simulation with the buttons of incrementing
and decrementing the values in the application. In today’s
article, we will be creating the action and reducers to
manipulate the state of the application. So, without further
ado let’s begin!
Getting Started
We are trying to understand Redux by building a simple
banking application. In our case, We would like to increase
the amount when the user clicks on the increment button
and decrease the amount when the client hits the
decrement button.
Installing Redux, React-redux and
redux-thunk
First of all, we will install Redux with some other important
redux libraries and the middlewares. We can easily do so by
using the below piece of code in the terminal:
OceanofPDF.com
Creating a Redux Store |
Complete React Course
Article #76
In the previous article, we have created the action and
reducers to manipulate the state of the application. In
today’s article, we will be combining all the reducers to work
as a single reducer function. In addition to this, we will be
going to create a Redux store for our application. So,
without further ado let’s begin!
In reducers folder- Index.js
First of all, we will create an index.js file that will combine all
the reducers to work as a single reducer function for the
application.
OceanofPDF.com
Accessing State in Redux |
Complete React Course
Article #77
In the previous article, we have combined all the reducers to
work as a single reducer function. In addition to this, we
have set up a Redux store for our React application. In this
article, we are going to understand how we can access the
State in Redux. So, without further ado let’s begin!
In Navbar.js - Accessing the Amount
State
Now, we will be using the use selector hook in Navbar.js to
access and use a specific state in the Navbar component.
The UseSelector hook allows us to get data from the Redux
store state, by defining a selector function. With the help of
the use selector hook, we can select any state from the
redux store to use it inside any component of our
application. Here’s the way of using the ‘useSelector’ hook:
Result
Hence, we have pulled the ‘amount’ from the created state
in the particular component, with the help of the use
selector hook. Remember, we are using the amount state in
the ‘Yourbalance’ button instead of the custom number. As a
result, the amount will be rendered as the value assigned in
the amount state. In our case, the initial value in the
amount state is 0. Therefore, we are getting the below
result:
OceanofPDF.com
Updating state from a
different component in
Redux | Complete React
Course Article #78
In the previous article, we have set up a Redux store for our
React application. In addition to this, we have learned how
we can access the state in Redux with the help of the use
selector hook. In today’s article, we are going to understand
how we can alter the state in Redux. So, without further ado
let’s begin!
Applying the useDispatch hook
Now we will dispatch the message from the action creators
to the reducer. In our case, the action creator will dispatch
the payload and type to the reducer, with the help of the
use dispatch hook. Hence, in our shop.js we will make the
below changes:
This was our last tutorial. Thank you for being with me
throughout the series. Keep learning and Keep Coding.
OceanofPDF.com