-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
39 lines (34 loc) · 1.3 KB
/
Copy pathApp.js
File metadata and controls
39 lines (34 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React from 'react';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import './App.css'; // Make sure App.css exists in src directory
import Header from './Components/Header'; // Adjust path based on your structure
import EmployeeForm from './Components/EmployeeForm'; // Adjust path based on your structure
import EmployeeDetail from './Components/EmployeeDetail'; // Adjust path based on your structure
import EmployeeList from './Components/EmployeeList'; // Adjust path based on your structure
function App() {
const [employees, setEmployees] = React.useState([]);
const addEmployee = (employee) => {
setEmployees([...employees, employee]);
};
const saveData = () => {
localStorage.setItem('employees', JSON.stringify(employees));
};
return (
<Router>
<div className="App">
<Header />
<Routes>
<Route path="/" element={
<>
<EmployeeForm onSubmit={addEmployee} />
<EmployeeList employees={employees} />
<button onClick={saveData}>Save Data</button>
</>
} />
<Route path="/employees/:id" element={<EmployeeDetail employees={employees} />} />
</Routes>
</div>
</Router>
);
}
export default App;