React Web Dev
React Web Dev
---------------------------------------
js library -> to create UI
impertitve approach in js but in react its easy herer you have to just say i want
this(it is also know as decelartive approcah)
State---------------------------------
useState is a React Hook that allows you to add state to functional components.
It’s used to manage dynamic data in your component that can change over time (such
as user input, a counter, or API data). The useState hook gives your component a
way to "remember" values between renders.
Initialize state inside your component: You call useState() and pass an initial
value as its argument. It returns an array with two values:
Fragments------------> React.Fragment
passing children--->
use ref
context api--->
jis v component ke andar \ likha hoga wo component render hone ke baad iske
andar jo v code likha hoga wo execute hoga
useeffect(()=>{ console,[]})
useeffect(()=>{ console,[text]})
the array hold the dependece
useEffect(() => {
const timer = setTimeout(() => {
console.log("Timeout triggered after 3 seconds");
}, 3000);
nav link do same thing and on clicked route ke upar active class laga dega
----------------------------------------
React advance--->class 1
custom hook
class-2 ---->
createContext()
provide context
consume
useSearchParam()
location.search
=======================================
redux calss 4
create a slice using createSlice(it gives reduceer and action creator) and it
contains
reducer:{
// name of slice counter:CounterSlice//reducer
},
})
const dispatch=useDispatch();