Skip to content

Commit 68baa76

Browse files
committed
Update the React Router Project
1 parent f01259e commit 68baa76

File tree

5 files changed

+62
-54
lines changed

5 files changed

+62
-54
lines changed

08_reactRouter/src/components/Contact/Contact.jsx

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,112 +18,112 @@ export default function Contact() {
1818
<svg
1919
fill='none'
2020
stroke='currentColor'
21-
stroke-linecap='round'
22-
stroke-linejoin='round'
23-
stroke-width='1.5'
21+
strokeLinecap='round'
22+
strokeLinejoin='round'
23+
strokeWidth='1.5'
2424
viewBox='0 0 24 24'
2525
className='w-8 h-8 text-gray-500'
2626
>
2727
<path
28-
stroke-linecap='round'
29-
stroke-linejoin='round'
30-
stroke-width='1.5'
28+
strokeLinecap='round'
29+
strokeLinejoin='round'
30+
strokeWidth='1.5'
3131
d='M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z'
3232
/>
3333
<path
34-
stroke-linecap='round'
35-
stroke-linejoin='round'
36-
stroke-width='1.5'
34+
strokeLinecap='round'
35+
strokeLinejoin='round'
36+
strokeWidth='1.5'
3737
d='M15 11a3 3 0 11-6 0 3 3 0 016 0z'
3838
/>
3939
</svg>
4040
<div className='ml-4 text-md tracking-wide font-semibold w-40'>
41-
Acme Inc, Street, State, Postal Code
41+
Wah Cantt , Rawalpandi
4242
</div>
4343
</div>
4444

4545
<div className='flex items-center mt-4 text-gray-600'>
4646
<svg
4747
fill='none'
4848
stroke='currentColor'
49-
stroke-linecap='round'
50-
stroke-linejoin='round'
51-
stroke-width='1.5'
49+
strokeLinecap='round'
50+
strokeLinejoin='round'
51+
strokeWidth='1.5'
5252
viewBox='0 0 24 24'
5353
className='w-8 h-8 text-gray-500'
5454
>
5555
<path
56-
stroke-linecap='round'
57-
stroke-linejoin='round'
58-
stroke-width='1.5'
56+
strokeLinecap='round'
57+
strokeLinejoin='round'
58+
strokeWidth='1.5'
5959
d='M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z'
6060
/>
6161
</svg>
6262
<div className='ml-4 text-md tracking-wide font-semibold w-40'>
63-
+44 1234567890
63+
+92-3106145445
6464
</div>
6565
</div>
6666

6767
<div className='flex items-center mt-2 text-gray-600'>
6868
<svg
6969
fill='none'
7070
stroke='currentColor'
71-
stroke-linecap='round'
72-
stroke-linejoin='round'
73-
stroke-width='1.5'
71+
strokeLinecap='round'
72+
strokeLinejoin='round'
73+
strokeWidth='1.5'
7474
viewBox='0 0 24 24'
7575
className='w-8 h-8 text-gray-500'
7676
>
7777
<path
78-
stroke-linecap='round'
79-
stroke-linejoin='round'
80-
stroke-width='1.5'
78+
strokeLinecap='round'
79+
strokeLinejoin='round'
80+
strokeWidth='1.5'
8181
d='M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z'
8282
/>
8383
</svg>
8484
<div className='ml-4 text-md tracking-wide font-semibold w-40'>
85-
85+
8686
</div>
8787
</div>
8888
</div>
8989

9090
<form className='p-6 flex flex-col justify-center'>
9191
<div className='flex flex-col'>
92-
<label for='name' className='hidden'>
92+
<label htmlFor='name' className='hidden'>
9393
Full Name
9494
</label>
9595
<input
9696
type='name'
9797
name='name'
9898
id='name'
9999
placeholder='Full Name'
100-
className='w-100 mt-2 py-3 px-3 rounded-lg bg-white border border-gray-400 text-gray-800 font-semibold focus:border-orange-500 focus:outline-none'
100+
className='w-full mt-2 py-3 px-3 rounded-lg bg-white border border-gray-400 text-gray-800 font-semibold focus:border-orange-500 focus:outline-none'
101101
/>
102102
</div>
103103

104104
<div className='flex flex-col mt-2'>
105-
<label for='email' className='hidden'>
105+
<label htmlFor='email' className='hidden'>
106106
Email
107107
</label>
108108
<input
109109
type='email'
110110
name='email'
111111
id='email'
112112
placeholder='Email'
113-
className='w-100 mt-2 py-3 px-3 rounded-lg bg-white border border-gray-400 text-gray-800 font-semibold focus:border-orange-500 focus:outline-none'
113+
className='w-full mt-2 py-3 px-3 rounded-lg bg-white border border-gray-400 text-gray-800 font-semibold focus:border-orange-500 focus:outline-none'
114114
/>
115115
</div>
116116

117117
<div className='flex flex-col mt-2'>
118-
<label for='tel' className='hidden'>
118+
<label htmlFor='tel' className='hidden'>
119119
Number
120120
</label>
121121
<input
122122
type='tel'
123123
name='tel'
124124
id='tel'
125125
placeholder='Telephone Number'
126-
className='w-100 mt-2 py-3 px-3 rounded-lg bg-white border border-gray-400 text-gray-800 font-semibold focus:border-orange-500 focus:outline-none'
126+
className='w-full mt-2 py-3 px-3 rounded-lg bg-white border border-gray-400 text-gray-800 font-semibold focus:border-orange-500 focus:outline-none'
127127
/>
128128
</div>
129129

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
import React, { useEffect } from 'react';
1+
// import React, { useEffect, useState } from 'react';
2+
import { useLoaderData } from 'react-router-dom';
23

34
function GitHub() {
4-
useEffect(() => {
5-
fetch('https://api.github.com/users/imran5244');
6-
}, []);
5+
const data = useLoaderData();
6+
// const [data, setData] = useState([]);
7+
// useEffect(() => {
8+
// fetch('https://api.github.com/users/imran5244')
9+
// .then((Response) => Response.json())
10+
// .then((data) => {
11+
// setData(data);
12+
// });
13+
// }, []);
714
return (
8-
<div className='text-center m-4 bg-gray-600 text-white p-4 text-3xl '>
9-
GitHub Followers
15+
<div className='text-center mx-auto mt-8 bg-gray-800 text-white p-8 rounded-lg shadow-lg max-w-md'>
16+
<img
17+
src={data.avatar_url}
18+
alt='GitHub Profile'
19+
className='rounded-full mb-4 mx-auto'
20+
style={{ width: '150px', height: '150px' }}
21+
/>
22+
<h2 className='text-3xl font-semibold mb-2'>
23+
GitHub Followers: {data.followers}
24+
</h2>
1025
</div>
1126
);
1227
}
1328

1429
export default GitHub;
30+
31+
export const githubInfoLoader = async () => {
32+
const respone = await fetch('https://api.github.com/users/imran5244');
33+
return respone.json();
34+
};

08_reactRouter/src/components/Header/Header.jsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { Link, NavLink } from 'react-router-dom';
32
export default function Header() {
43
return (
@@ -79,18 +78,6 @@ export default function Header() {
7978
GitHub
8079
</NavLink>
8180
</li>
82-
<li>
83-
<NavLink
84-
to='/user'
85-
className={({ isActive }) =>
86-
`block py-2 pr-4 pl-3 duration-200
87-
${isActive ? 'text-orange-700' : 'text-gray-700'}
88-
border-b border-gray-100 hover:bg-gray-50 lg:hover:bg-transparent lg:border-0 hover:text-orange-700 lg:p-0`
89-
}
90-
>
91-
User
92-
</NavLink>
93-
</li>
9481
</ul>
9582
</div>
9683
</div>

08_reactRouter/src/components/User/User.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React from 'react';
21
import { useParams } from 'react-router-dom';
32

43
function User() {
54
const { userid } = useParams();
5+
66
return (
77
<div className='bg-gray-600 text-white text-3xl p-4 text-center '>
8-
User:{userid}
8+
User: {userid}
99
</div>
1010
);
1111
}

08_reactRouter/src/main.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Home from './components/Home/Home.jsx';
1212
import About from './components/About/About.jsx';
1313
import Contact from './components/Contact/Contact.jsx';
1414
import User from './components/User/User.jsx';
15-
import GitHub from './components/GitHub/GitHub.jsx';
15+
import GitHub, { githubInfoLoader } from './components/GitHub/GitHub.jsx';
1616

1717
// const router = createBrowserRouter([
1818
// {
@@ -41,8 +41,9 @@ const router = createBrowserRouter(
4141
<Route path='' element={<Home />} />
4242
<Route path='about' element={<About />} />
4343
<Route path='contact' element={<Contact />} />
44-
<Route path='user/ :userid' element={<User />} />
45-
<Route path='github' element={<GitHub />} />
44+
<Route path='/user/:userid' component={User} />
45+
46+
<Route loader={githubInfoLoader} path='github' element={<GitHub />} />
4647
</Route>
4748
)
4849
);

0 commit comments

Comments
 (0)