aboutsummaryrefslogtreecommitdiff
path: root/src/ReplyForm.js
diff options
context:
space:
mode:
authorLibravatar Renard 2019-09-16 01:53:15 -0300
committerLibravatar Renard 2019-09-16 01:53:15 -0300
commit464d949467c4c16bd396661d3880813d0cba6f3b (patch)
tree7ceeb4d03be15d9c8f11f7502adbae23effa4f4c /src/ReplyForm.js
parentcd9b802b71df4e2701e2311b2995fe70a9692ae4 (diff)
downloadbai-client-464d949467c4c16bd396661d3880813d0cba6f3b.tar.gz
bai-client-464d949467c4c16bd396661d3880813d0cba6f3b.tar.xz
bai-client-464d949467c4c16bd396661d3880813d0cba6f3b.zip
setState is async
Diffstat (limited to 'src/ReplyForm.js')
-rw-r--r--src/ReplyForm.js77
1 files changed, 44 insertions, 33 deletions
diff --git a/src/ReplyForm.js b/src/ReplyForm.js
index 33a6af4..6695406 100644
--- a/src/ReplyForm.js
+++ b/src/ReplyForm.js
@@ -24,41 +24,52 @@ class ReplyForm extends Component {
}
handleSubmit() {
- const { submittedName, submittedEmail, name, email, message } = this.state;
- this.setState({
- submittedName: name,
- submittedEmail: email,
- submittedMessage: message
- });
- const data = {
- board: this.props.dir,
- parent: this.props.parent,
- name: "",
- email: "",
- fielda: submittedName,
- fieldb: submittedEmail,
- message: message,
- password: "bai-client"
- };
+ const {
+ submittedName,
+ submittedEmail,
+ submittedMessage,
+ name,
+ email,
+ message
+ } = this.state;
+ this.setState(
+ {
+ submittedName: name,
+ submittedEmail: email,
+ submittedMessage: message
+ },
+ () => {
+ const data = {
+ board: this.props.dir,
+ parent: this.props.parent,
+ name: "",
+ email: "",
+ fielda: submittedName,
+ fieldb: submittedEmail,
+ message: submittedMessage,
+ password: "bai-client"
+ };
- const formData = new FormData();
- for (var key in data) {
- formData.append(key, data[key]);
- }
+ const formData = new FormData();
+ for (var key in data) {
+ formData.append(key, data[key]);
+ }
- fetch("https://bienvenidoainternet.org/cgi/api/post", {
- method: "POST",
- mode: "cors",
- redirect: "follow",
- body: formData
- })
- .then(response => {
- return response.json();
- })
- .then(resource => {
- console.log(resource);
- this.setState({ replyRes: resource });
- });
+ fetch("https://bienvenidoainternet.org/cgi/api/post", {
+ method: "POST",
+ mode: "cors",
+ redirect: "follow",
+ body: formData
+ })
+ .then(response => {
+ return response.json();
+ })
+ .then(resource => {
+ console.log(resource);
+ this.setState({ replyRes: resource });
+ });
+ }
+ );
}
render() {