Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions my-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "my-project",
"version": "0.1.0",
"private": true
}
17,430 changes: 17,430 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"tailwindcss": "^3.4.1"
}
}
1 change: 1 addition & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

8 changes: 6 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import "./App.css";

import Item from "./components/Item";
function App() {
return <div></div>;
return (
<div>
<Item />
</div>
);
}

export default App;
31 changes: 31 additions & 0 deletions src/components/Item.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import UseToggle from "../hooks/UseToggle";

function Item() {
const [ Infor, isLoading] = UseToggle();
return (
<div className="m-20 flex justify-around items-center flex-wrap gap-12">
{isLoading ? (
<p>Loading</p>
) : (
Infor?.map((info) => {
return (
<div
key={info.id}
className="w-[380px] h-44 border-solid border-2 border-black rounded-3xl size text-xl flex flex-col items-center shadow-cards
transition ease-in-out delay-150 bg-one hover:-translate-y-1 hover:scale-110 hover: duration-300 "
>
<h2 className=" m-5 w-full text-center text-3xl font-bold ">
{info.name}
</h2>
<p>{info.email}</p>
<p>{info.phone}</p>
<p>{info.company.name}</p>
</div>
);
})
)}
</div>
);
}
export default Item;
32 changes: 32 additions & 0 deletions src/components/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.hader {
margin: 20px;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
gap: 50px;
}
.cards {
width: 350px;
background-color: #fecda6;
border: 3px solid #ffffff;
border-radius: 25px;
font-size: larger;
text-align: center;
transition: all 0.5s;

/_ box-shadow: inset 46px 42px 36px 35px rgba(0, 0, 0, 0.1); _/
box-shadow: 10px 20px 20px 20px rgba(0, 0, 0, 0.1);
}
.cards:hover {
border: 3px solid black;
transform: scale(1.05);
}

.cards:active {
transform: scale(0.95) rotateZ(1.7deg);
}
.name {
background-color: #ff5b22;
/_ color: #ff5b22; _/
}
26 changes: 26 additions & 0 deletions src/hooks/UseToggle.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useEffect, useState } from "react";
function UseToggle() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you create a react hook, you have to name it correctly, with the use lower-cased.

Additionally, when creating a new hook please make sure you name it carefully.
useToggle is not really a fitting name in this case, because we are not toggling anything.
Instead name it into something like useFetchData or useFetch.

const [Infor, setInfor] = useState([]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you create a new state, make sure you follow the naming conventions.
the value and setter should be in camel case:

const [infor, setInfor] = useState([]);

const [isLoading, setIsLoading] = useState(false);

const fetchData = async () => {
try {
setIsLoading(true);
const response = await fetch(
"https://jsonplaceholder.typicode.com/users"
);
if (response.ok) {
const data = await response.json();
setInfor(data);
setIsLoading(false);
} else console.log("error");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the else clause, you should set isLoading to false, not doing so would make isLoading always true in case an error happens.

if (response.ok) {
        const data = await response.json();
        setInfor(data);
        setIsLoading(false);
      } else {
        console.log("error");
        setIsLoading(false);
      }

or

if (response.ok) {
        const data = await response.json();
        setInfor(data);
      } else {
        console.log("error");
     }
    setIsLoading(false);

} catch (error) {
console.log("error massage", error);
}
};
useEffect(() => {
fetchData();
}, []);
return [fetchData, Infor, isLoading];
}
export default UseToggle;
14 changes: 7 additions & 7 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
/* background-color: #a9a9a9; */
}
21 changes: 21 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{js,jsx}"],

theme: {
extend: {
colors: {
one: "#fecda6",
two: "#ff5b22",
},
spacing: {
350: "350px",
},
boxShadow: {
cards: " 10px 20px 20px 20px rgba(0, 0, 0, 0.1)",
},
},
},

plugins: [],
};
Loading