Skip to content

swara-2006/learnings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

React Hooks

1)Usestate hook const [time,setTime]=useState(new Date())

i.setCount(prev=>prev+1)

ii.onClick={()=>{random_color();countChange();}} //Way to add two functions at a time to listener.

iii.onKeyDown={(e)=>{ if(e.key==='Enter') {InputCount();} }}/>

2)UseEffect hook

i.| Dependency Array | Behavior | | ------------------- | ---------------------------------- | | [] | Run only once (after first render) | | [someVar] | Run when someVar changes | | (no array at all) | Run on every render |

ii.

What you want to do useEffectpattern
Do something once on mount useEffect(() => { ... }, []);
Do something when a variable changes useEffect(() => { ... }, [value]);
Cleanup something (like a timer) return () => { cleanup } inside it

//Random -Fetching API const fetch_data= async () => { const response= await fetch("https://randomuser.me/api") const data=await response.json() console.log(data);

setUser(data.results[0])

}

if u have set your useState initial as null then before fetching api first check if data is available. {user?(

User name :{user.name.first} {user.name.last}

User email :{user.email}

Gender :{user.gender}

location : {user.location.city},{user.location.state}

): (

Still loading..........

)}

//React Router:

About

A comprehensive collection of essential React concepts and examples I've learned while exploring React deeply. This repository serves as a clear, beginner-friendly guide to understanding and applying React logic confidently—without confusion. Ideal for revising core ideas and mastering React in a structured way.Thank me later :)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors