From 629557fcc8b2561e77c1b9e53f79aabe814fd9c7 Mon Sep 17 00:00:00 2001 From: Renard Date: Mon, 23 Sep 2019 12:33:09 -0300 Subject: Datos de usuario persistentes --- src/ReplyForm.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/ReplyForm.js') diff --git a/src/ReplyForm.js b/src/ReplyForm.js index 9220501..8c942e7 100644 --- a/src/ReplyForm.js +++ b/src/ReplyForm.js @@ -22,6 +22,13 @@ class ReplyForm extends Component { this.handleSubmit = this.handleSubmit.bind(this); } + componentWillMount() { + let userData = JSON.parse(localStorage.getItem("userData")); + if (userData != null) { + this.setState({ name: userData.name, email: userData.email }); + } + } + handleChange(e) { const { name, value } = e.target; this.setState({ [name]: value }); @@ -48,6 +55,9 @@ class ReplyForm extends Component { password: "bai-client" }; + let userData = { name: name, email: email }; + localStorage.setItem("userData", JSON.stringify(userData)); + const formData = new FormData(); for (var key in data) { formData.append(key, data[key]); @@ -63,7 +73,7 @@ class ReplyForm extends Component { return response.json(); }) .then(resource => { - this.setState({ replyRes: resource }); + this.setState({ replyRes: resource, message: "" }); }); } ); -- cgit v1.2.1-18-gbd029