- UI library (not technically a framework)
- Developed originally by Facebook (now Meta)
- Used for client side rendering
- Install
node.js
first - We will be using
Vite
instead ofcreate-react-app
- Vite will help us with setting up a complete react project
- Steps:
npm create vite@latest frontend
- Select
react
and thenJavaScript
cd frontend
to go into the newly createdfrontend
foldernpm install
to install all the needed node packages
index.html
:- this is the file sent to the browser
- The whole app is rendered inside this one file
package.json
- holds information about any node project
- also has the node scripts we use to run and build the project
node_modules
folder:- contains all the dependencies
- created when we ran
npm install
public
:- contains any static assets our app will need
src
folder:- contains all the source code of our app
- this is where the bulk of our work
vite.config.js
:- a config file for Vite.js
.gitignore
:- used to prevent some files from being tracked by git
npm run dev
will run our app- if all works fine, you will see a URL of where the app is hosted locally (it was
http://localhost:5173
for me) - opening the URL will show you a page created using ReactJS
- this is the default demo app
- click on the
count is 0
text to increase the count!
- Now, lets try something cool
- Go to the
src
folder and open theApp.jsx
file - Try changing some text, eg. change the text
Vite + React
toLUG VITC ROCKS!!!
- After making the change, save the file.
- You will see that the web app will automatically reload and our changes are reflected without us having to reload the page
- This is called Hot Module Reloading or HMR
- This feature helps speed up development by eliminating the need to reload the app every time we make a change
- The demo app is cool, but if we want to make our own app, we will need to remove the demo code before we can write our own.
- To clear the demo app, do the following stuff:
App.jsx
:- replace everything inside the App function and replace it with
return <>LUG VITC ROCKS!!!</>;
- also remove lines 1, 2 and 3
- replace everything inside the App function and replace it with
- empty
App.css
andindex.css
- render on state change
- virtual dom
- it is jsx!
- a special syntax to write html-like markup inside js
- inside curly braced
- &&, || and ?: