Hello dear , there is an error in the code below, I have reviewed it many times but dont get it
would you please check it
import axios, { CanceledError } from “axios”;
import { useEffect, useState } from “react”;
interface User {
id: number;
name: string;
}
const App = () => {
const [users, setUsers] = useState<User>();
const [Error, setError] = useState(“”);
const [Loading, setLoading] = useState(false);
useEffect(() => {
const controler = new AbortController();
setLoading(true);
axios
.get<User>(“https://jsonplaceholder.typicode.com/users”, {
signal: controler.signal,
})
.then((res) => {
setUsers(res.data);
setLoading(false);
})
.catch((err) => {
if (err instanceof CanceledError) return;
setError(err.message);
setLoading(false);
});
return () => controler.abort();
}, );
const AddUser = () => {
const orginalusers = […users];
const newUser = { id: 0, name: “Razieh Berah” };
setUsers([newUser, …users]);
axios
.post(“https://jsonplaceholder.typicode.com/users/”, newUser)
.then((res) => setUsers([res.data, …users]))
.catch((err) => {
setError(err.message);
setUsers(orginalusers);
});
};
const DeleteUser = (user: User) => {
const orginalusers = […users];
setUsers(users.filter((u) => u.id !== user.id));
axios
.delete("https://jsonplaceholder.typicode.com/users/" + user.id)
.catch((err) => {
setError(err.message);
setUsers(orginalusers);
});
};
return (
{Loading && }
{Error &&
{Error}
}Add
{u.name}
Update
<button
className=“btn btn-outline-danger”
onClick={() => DeleteUser(user)}
//**here is the problem which say the user in unclear //
>
Delete
{users.map((u) => (
))}
);
};
export default App;