week 7.1 routeing, lazy component, prop drilling, contextAPI

//create a react project
1. npm install
2. npm install react-router-dom  //for using react routing
//create page OR component folder inside create 2page landing.jsx and dashboard.jsx

-----------------------------------------------------------

//then we use navigation to use client side route

/ first import usenavigation

import { BrowserRouter, Routes, Route, useNavigate } from 'react-router-dom';


// definre up from the syntx you write

const navigate = useNavigate();


then syntax**  

<button onClick={() => {

          navigate("/");

        }}>Landing</button>

--------------------------------------------------------------


+++++++++++++++++++++++++++++
now we will do only client side routing do not hard refresh like before we did

//then we use navigation to use client side route
/ first import usenavigation
import { BrowserRouter, Routes, Route, useNavigate } from 'react-router-dom';

// definre up from the syntx you write
const navigate = useNavigate();
// app.js
//then syntax**  
<button onClick={() => {
          navigate("/");
        }}>Landing</button>


&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
lazy landing
Now that your component’s code loads on demand, you also need to specify what should be displayed while it is loading. You can do this by wrapping the lazy component or any of its parents into a <Suspense> boundary:

+++++++++++++++++++++++++++++

app.jsx

//syntax***
import { lazy } from "react";
const Dashboard = lazy(() => import ( './pages/Dashboard'));
const Landing = lazy(() => import ( './pages/Landing'));

<Route path="/dashboard" element={<Suspense fallback={"loading..."}><Dashboard /></Suspense>} />
<Route path="/" element={<Suspense fallback={"loading..."}><Landing /></Suspense>} />

//Suspense API, asynchronous component fetching,  asynchronous data fetching-

====================================================================

//prop drilling
// thumb rule* always store date in least common ansister
//Passing props is a great way to explicitly pipe data through your UI tree to the components that use it.
But passing props can become verbose and inconvenient when you need to pass some prop deeply through 
the tree, or if many components need the same prop. The nearest common ancestor could be far removed from
the component's that need data,  and lifting state up that high can lead to a situation called "prop drilling".

================================================================

//context API
If you use the context api, you're pushing your state management outsid the code react components
OR context api is use fro fix prop drilling mesh in prop imagine a root tree that have a1 and a2, a1 have child b1
that mean when you working with a2 and b1 you need to make pipe line to rech on your root tree you cant telepoat directly to root tree to b1 or a2 .
first you use App() then you use a1 where you also need to just pass  the parameter  the b1 will be able to access if 
you want without passing root tree to b1 you have only error


import { createContext } from "react";
export const countContext = createContext(0);

Comments

Popular posts from this blog

CyberSecurity

VERTICAL SCALING 💋

prisma using in project idx 13.3