Step by Step Guide - Ecommerce Website Using React and Django
Step by Step Guide - Ecommerce Website Using React and Django
4. Setup React
● Install Node
● Create new react app using vite.js (for better performance and load time)
● Install primary react packages/dependencies (Check package.json)
● Spin up the dev server - Tada!!
Requirments
Using Vite to set up a React project is often a better choice than Create React App
(CRA) for a simpler reason – speed and efficiency. Vite's development server is
notably faster, meaning you spend less time waiting for your changes to take effect.
It also creates smaller, more efficient code bundles, which results in faster page
loads for your website visitors. Vite's configuration is straightforward, and it doesn't
include unnecessary code for older browsers, which can make your site faster and
more modern. Additionally, Vite is designed to work well with both Vue and React,
offering you a fast and versatile tool for building web applications. Ultimately, it's
about choosing a tool that makes your development process faster and smoother.
yarn
yarn dev
Let’s Continue:
● For creating a zustang user store. Create a folder in src named store &
create a file named auth.js inside it.
This store keeps track of user info, such as whether they're logged in or not.
You can use a user function to find out the ID and username of the logged-in
user. Once everything is set up, you can use DevTools to check the store's
info in real-time.
Now, let's create utility functions that we will require for authentication
purpose.
We will create utils folder inside src folder.
We will create 4 files, auth.js axios.js constants.js useAxios.js
token is still valid before sending a request to the server. If it's not valid, we
should request a new token using a refresh token. Once we get a new
access token, we can use it for API requests to private routes. If the token is
How to Implement: We can solve this issue by using the axios library, which
requests before they are sent to the server. Therefore, we should use axios
/login
/register
/
/protected — Private Route
/logout — Log user out
If the user is logged in, they only should be able to access the private route,
Create a folder at frontend root, named layouts add these 2 files in it.
The MainWrapper is like a big container that holds the whole app together.
It's the one that tells the app who the user is.
PrivateRoute is like a security guard. It checks if the user is logged in. If they
are, it lets them go to the page they want. If not, it sends them to the login
page.
Now that we've done the tough part, we need to use this in the app. We
need to make pages and parts of the app.
88. Earning(API)
● Create a new Earning ListApiView
● Configure the view in the url
● Test ;)
89. Monthly Earning(API)
● Create a new Monthly Earning List (fbv so we can use it for chart)
● Configure the view in the url
● Test ;)
90. Earning(Client)
● Fetch the new earning data via the earning list api view
● Set the values to the state
● Render Required Data in the frontend