Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a "View Profile" button that links directly to the displayed GitHub user's profile. #244

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 35 additions & 20 deletions 07reactRouter/src/components/Github/Github.jsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
import React, { useEffect, useState } from 'react'
import { useLoaderData } from 'react-router-dom'
import React, { useEffect, useState } from "react";
import { useLoaderData } from "react-router-dom";

function Github() {
const data = useLoaderData()
// const [data, setData] = useState([])
// useEffect(() => {
// fetch('https://api.github.com/users/hiteshchoudhary')
// .then(response => response.json())
// .then(data => {
// console.log(data);
// setData(data)
// })
// }, [])
const data = useLoaderData();
// const [data, setData] = useState([])
// useEffect(() => {
// fetch('https://api.github.com/users/hiteshchoudhary')
// .then(response => response.json())
// .then(data => {
// console.log(data);
// setData(data)
// })
// }, [])

return (
<div className='text-center m-4 bg-gray-600 text-white p-4 text-3xl'>Github followers: {data.followers}
<img src={data.avatar_url} alt="Git picture" width={300} />
<div className='text-center m-4 bg-gray-600 text-white p-4 text-3xl'>
Github followers: {data.followers}
<img
src={data.avatar_url}
alt='Git picture'
width={300}
className='rounded-full flex justify-center items-center mx-auto'
/>
<a
href={`https://github.com/${data.login}`}
target='_blank'
rel='noopener noreferrer'
>
<button className='bg-white text-gray-800 px-4 py-2 rounded-md'>
View Profile
</button>
</a>
</div>
)
);
}

export default Github
export default Github;

export const githubInfoLoader = async () => {
const response = await fetch('https://api.github.com/users/hiteshchoudhary')
return response.json()
}
const response = await fetch("https://api.github.com/users/hiteshchoudhary");
return response.json();
};