REACT JS
REACT JS FEATURES
REACT JS ADVANTAGES
REACT JS ARCHITECTURE
REACT JS ARCHITECTURE
CREATING REACT APP
CREATING REACT APP
RUN REACT APP
JSX
JSX Expressions
JSX Expressions
Index.html
<!doctype html> <html lang="en"> <body> <div id="root"></div> <script type="module" src="/src/main.jsx"></script> </body> </html> �
Main.jsx
import { createRoot } from 'react-dom/client' function Car() { return ( <> <h1>My car</h1> <p>It has {218 * 1.36} horsepower</p> </> ); } createRoot(document.getElementById('root')).render( <Car /> );
�
JSX Expressions
Variables are also valid expressions. Insert variables in JSX by wrapping it in curly braces { }.
<!doctype html> <html lang="en"> <body> <div id="root"></div> <script type="module" src="/src/main.jsx"></script> </body> </html>
import { createRoot } from 'react-dom/client' function Car() { const hp = 218 * 1.36; return ( <> <h1>My car</h1> <p>It has {hp} horsepower</p> </> ); } createRoot(document.getElementById('root')).render( <Car /> );
REACT COMPONENTS
Creating Components
Rendering Components
Now your React application has a component called Car, which returns an <h2> element.
To use this component in your application, refer to it like this: <Car />
<!doctype html> <html lang="en"> <body> <div id="root"></div> <script type="module" src="/src/main.jsx"></script> </body> </html>
import { createRoot } from 'react-dom/client' function Car() { return ( <h2>Hi, I am a Car!</h2> ); } createRoot(document.getElementById('root')).render( <Car /> ); �
�
Components in Components
Props
Props Children
<!doctype html> <html lang="en"> <body> <div id="root"></div> <script type="module" src="/src/main.jsx"></script> </body> </html>
import { createRoot } from 'react-dom/client' function Son(props) { return ( <div style={{background: 'lightgreen'}}> <h2>Son</h2> <div>{props.children}</div> </div> ); } function Daughter(props) { const {brand, model} = props; return ( <div style={{background: 'lightblue'}}> <h2>Daughter</h2> <div>{props.children}</div> </div> ); } function Parent() { return ( <div> <h1>My two Children</h1> <Son> <p> This was written in the Parent component, but displayed as a part of the Son component </p> </Son> <Daughter> <p> This was written in the Parent component, but displayed as a part of the Daughter component </p> </Daughter> </div> ); } createRoot(document.getElementById('root')).render( <Parent /> );
React Events
React Events
React Forms
�
React Forms
Fetch
Fetch
Syntax
fetch('url-to-resource') .then(response => { // Handle the response here }) .catch(error => { // Handle errors here });
Axios
Axios
Syntax
axios.get('url') .then((response) => { // Code for handling the response }) .catch((error) => { // Code for handling the error })
React Router
Installing React Router
function App() { return ( <BrowserRouter> {/* Your app content */} </BrowserRouter> ); }
Components of React Router
Nested Routes