28
loading...
This website collects cookies to deliver better user experience
import {useEffect, useState} from 'react';
const [githubData, setGithubData] = useState([])
const [githubUser, setGithubUser] = useState("vikstack")
const fetchData = () => {
return fetch(`https://api.github.com/users/${githubUser}`)
.then((response) => response.json())
.then((data) => setGithubData(data));
}
https://api.github.com/users/[username] // you can open and check whats in this url
and then setting githubData and the response data from our api.useEffect(() => {
fetchData()
}, [])
// these code are inside return()
<input type="text" placeholder="Search for User" onChange={(e) => setGithubUser(e.target.value)} className="input_search" />
<button onClick={fetchData} className="search_button">Search Github</button>
<img src={githubUser.avatar_url} height="100" width="100" />
<p>{githubUser.name}</p>
https://api.github.com/users/[username]
and replace {githubUser.name}
to {githubUser.[something in the url]}
like {githubUser.location}