js
js
js` cần thiết để bạn có thể copy và chạy trên Visual Studio Code với Node.js và
React:
---
### 1. **App.js**
```javascript
function App() {
return (
<Router>
<Switch>
</Switch>
</Router>
);
```
---
### 2. **Home.js**
```javascript
useEffect(() => {
// Load student data from the database.json (replace '/path/to/database.json' with the correct path)
fetch('/path/to/database.json')
.then((data) => {
setStudents(studentData);
setMajors(uniqueMajors);
});
}, []);
fetch('/path/to/database.json')
.then((data) => {
setStudents(filteredStudents);
});
};
return (
<div className="home">
<h1>Student List</h1>
<div>
<h2>Majors</h2>
<ul>
{major}
</li>
))}
</ul>
</div>
<div>
<ul>
{students.map((student) => (
<li key={student.id}>
{student.fullName} - {student.major}
<Link to={`/student/${student.code}`}>Detail</Link>
</li>
))}
</ul>
</div>
</div>
);
};
export default Home;
```
---
### 3. **StudentDetail.js**
```javascript
useEffect(() => {
fetch('/path/to/database.json')
.then((data) => {
setStudent(studentDetail);
if (studentSubjects) {
});
setSubjects(subjectNames);
});
}, [code]);
};
return (
<div>
<h1>{student.fullName}</h1>
<h2>CPA: {student.cpa}</h2>
<h3>Subjects</h3>
<input
type="text"
placeholder="Search subjects"
/>
<ul>
{subjects
<li key={index}>{subject}</li>
))}
</ul>
<input
type="text"
placeholder="New Subject"
value={searchTerm}
/>
</div>
);
};
```
---
```
- src/
- App.js
- Home.js
- StudentDetail.js
- public/
- database.json (Place this file here or adjust the path in fetch API calls)
```
Ensure that `database.json` is placed in the correct location as specified in the fetch request. You may
need to use a relative path like `/database.json` if it's in your `public` folder.