ky
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import React from "react";
|
||||
import op from "object-path";
|
||||
import config from "~/config";
|
||||
import ky from "ky";
|
||||
// const config = {
|
||||
// title: "Hello World",
|
||||
// description: "Hello World description",
|
||||
@@ -17,11 +18,31 @@ const data = {
|
||||
};
|
||||
|
||||
const HelloWorld: React.FC = () => {
|
||||
const [state, setState] = React.useState([]);
|
||||
React.useEffect(() => {
|
||||
ky.get("https://jsonplaceholder.typicode.com/todos/")
|
||||
.json()
|
||||
.then((data) => {
|
||||
setState(data);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<strong>Hello World !</strong>
|
||||
<p>{data.description}</p>
|
||||
<p>Name: {op.get(data, "og.title")}</p>
|
||||
|
||||
<div>
|
||||
<h3>TODO Data</h3>
|
||||
<ul>
|
||||
{state.map((item, index) => (
|
||||
<li key={index}>
|
||||
{item.completed ? "✅" : "🤷"} - {item.title} (#{item.id})
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"react": "^18.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ky": "^1.2.2",
|
||||
"object-path": "^0.11.8"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user