📅  最后修改于: 2022-03-11 15:00:40.539000             🧑  作者: Mango
class App extends React.Component {
state = {
post: {
name: "",
description: ""
},
jobs: []
};
handleChange = e => {
const { name, value } = e.target;
this.setState(prevState => ({
post: { ...prevState.post, [name]: value }
}));
};
handleSubmit = e => {
e.preventDefault();
this.setState(prevState => ({
jobs: [...prevState.jobs, prevState.post],
post: { name: "", description: "" }
}));
};
render() {
return (
Welcome to React
{this.state.jobs.map((job, index) => (
-
{job.name}: {job.description}
))}
);
}
}
ReactDOM.render( , document.getElementById("root"));