export default Person|Hooks
¢ Hooks are pre-defined functions.
¢ Rendering:- sbse pehli baar nazar ana.
¢ Rerendering:- dom me kuch change krna , uska reflect in main UI ,
that is called rerendering.
¢ In react i can't change the value directly.
useState() hook:
(Note: The state is a fancy name for the variable.)
* useState is a hook.
* useState is a function and it returns me an array with two elements.
The first is the state (counter) and the second is a function
(setCounter) (jiski madat se state change hoga).¢ We cannot change state directly we need a function for that.
¢ Any change in state done bt the setCounter is observed by the
component and that component will rerender itself.
¢ When we run the useState function it accepts an initial value(it can be
anything). > number, string, empty array, and object, etc.
let [counter, setCounter] = useState(5useEffect()
¢ It is a hook
¢ that accepts two things > callback function and dependecy array.
¢ dependecy array [state/props]— vo chije daalte hai jinke change
hone se hmara useeffect fir se chita hai.
¢ Fetching data from APIs.
Why do we use UseEffect?
¢ It is used for running side effects that do not directly affect the DOM
(e.g., fetching data, updating the document title, etc.).
¢ React ensures that we tell it what we depend on when using
useEffect. If we are using any state or prop inside the effect, we
must mention them in the dependency array.useEffect(() => {
console.log("This will run when ‘count’ changes");
3, [count]);