ReactJS Simple Program
Frontend File: [Link]
import React, { useEffect, useState } from 'react';
function App() {
const [students, setStudents] = useState([]);
const [form, setForm] = useState({ name: '', age: '', email: '' });
useEffect(() => {
fetch('[Link]
.then(res => [Link]())
.then(data => setStudents(data));
}, []);
const handleSubmit = (e) => {
[Link]();
fetch('[Link] {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: [Link](form)
}).then(() => [Link]());
};
return (
<div style={{ padding: 20 }}>
<h2>Student Form</h2>
<form onSubmit={handleSubmit}>
<input
placeholder="Name"
onChange={e => setForm({ ...form, name: [Link] })}
/>
<input
type="number"
placeholder="Age"
onChange={e => setForm({ ...form, age: +[Link] })}
/>
<input
placeholder="Email"
onChange={e => setForm({ ...form, email: [Link] })}
/>
<button type="submit">Add</button>
</form>
<h3>Student List</h3>
<ul>
{[Link]((s, i) => (
<li key={i}>
{[Link]} ({[Link]}) - {[Link]}
</li>
ReactJS Simple Program
))}
</ul>
</div>
);
}
export default App;