A React + TypeScript application that consumes an external API to fetch users and allows adding, editing, and deleting users locally, with form validation, loading state, and portal-based overlay.
✅ Fetch users from an external API ✅ Global loading state with overlay (Portal) ✅ Error handling ✅ Add new users ✅ Edit existing users ✅ Delete users with confirmation ✅ Form validation ✅ Simple and functional UI ✅ Fully typed with TypeScript
- React
- TypeScript
- Axios
- React DOM Portals
- CSS / Utility Classes
- JSONPlaceholder API
https://jsonplaceholder.typicode.com/usersUsed only to fetch the initial list of users. All create, update, and delete operations are handled locally in state.
src/
│
├── App.tsx
├── App.css
└── main.tsxnpm install
# or
pnpm installnpm run dev
# or
pnpm devThe application will be available at:
http://localhost:3000type User = {
id: string;
name: string;
username: string;
email: string;
phone: string;
};useEffect(() => {
setLoading(true);
axios
.get(apiURL)
.then(({ data }) => setUsers(data))
.catch(() => setError('Error loading users'))
.finally(() => setLoading(false));
}, []);const isFormValid =
userName.trim() &&
userUsername.trim() &&
userEmail.trim() &&
userPhone.trim();const addUser = () => {
const newUser = {
id: crypto.randomUUID(),
name: userName,
username: userUsername,
email: userEmail,
phone: userPhone,
};
setUsers((prev) => [...prev, newUser]);
};const saveEdit = () => {
setUsers((prev) =>
prev.map((user) =>
user.id === editingId ? { ...user, name, username, email, phone } : user
)
);
};const deleteUser = (userId: string) => {
if (window.confirm('Are you sure you want to delete this user?')) {
setUsers((prev) => prev.filter((user) => user.id !== userId));
}
};{loading &&
createPortal(
<div className="fixed inset-0 bg-black/40 flex items-center justify-center">
Loading...
</div>,
document.body
)}## 📸 Screenshot
- 🔄 Real backend integration (full CRUD)
- ✅ Advanced validation with regex
- 📱 Improved mobile responsiveness
- 🧪 Unit and integration tests (Jest / Vitest)
- 🔐 Authentication
- 📦 Pagination and search
This project is open for learning and portfolio purposes.