1. What is React JS?
React JS is a JavaScript library used to build interactive and dynamic user interfaces.
For example:
- Blog websites
- E-commerce websites
- Social media applications
- Admin dashboards
- Student management systems.
React was developed by Facebook (Meta).
JSX
React files are in the extension of .jsx format.JSX- java script XML
XML-eXtensible Markup Language(we use user-defined tags like new tags)
HTML-Hypertext markup Language(we use only pre-defined tags)
Before starting react project we need to install nodejs where we get npm-node package manager from it we need to install react.
Commands used to install
#Check node is installed: node -v npm -v #Create React Project using Vite npm create vite@latest my-react-app #Select options Framework: React Variant: JavaScript #Move into project folder cd my-react-app #Install dependencies npm install #Run React project npm run dev #Open browser http://localhost:5173/ Additional Library install commands
npm install axios--->Install Axios npm install react-router-dom--->Install React Router npm install bootstrap--->Install Bootstrap npm install lucide-react--->Install icons npm run build--->Create production build npm run preview--->Preview production build *Rules to Follow in react *
- Component names-Must start with capital letters.(eg.Header.jsx)
- JSX-Return one parent element and close all tags.
- CSS classes-Use className instead of class.
<div className="blog-card"> <h2>React Basics</h2> </div>
plaintext
- JavaScript expressions-Use curly braces {} inside JSX.
function Blog() { const title = "Introduction to React" return ( <div> <h1>{title}</h1> </div> ) }
plaintext
- State-Update state using setter functions.
import { useState } from 'react' function Blog() { const [like, setLike] = useState(0)#setLike IS SETTER FUNCTION return ( <div> <h2>My Blog</h2> <h3>Likes: {like}</h3> <button onClick={() => setLike(like + 1)}> Like </button> </div> ) } export default Blog
plaintext
- Hooks-Call hooks at the top level.
- Events-Use camelCase event names.
Javascript React onclick onClick onchange onChange onsubmit onSubmit onmouseover onMouseOver onkeydown onKeyDown - Import/Export-Use correct component paths.
- Files-Use .jsx for component files.
![Motion Planning and Navigation — Ch.11: Legged Robot Navigation [KR]](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqftgs44jxvhe8fxlcrvt.png)