diff --git a/src/components/Profile/ProfileForm.js b/src/components/Profile/ProfileForm.js
index 9f6d1853..424debd0 100644
--- a/src/components/Profile/ProfileForm.js
+++ b/src/components/Profile/ProfileForm.js
@@ -1,24 +1,24 @@
-/* In this component, we'll handle forms.
- * React handles forms quite differently.
+/* In this component, we'll handle forms.
+ * React handles forms quite differently.
* You'll need to handle the changes when you input something to the form.
- *
+ *
* Activity:
- * Modify this component to create your form.
+ * Modify this component to create your form.
* Add new fields, new form elements
* Create a function that logs the form results.
- *
- * Reference: https://reactjs.org/docs/forms.html
+ *
+ * Reference: https://reactjs.org/docs/forms.html
*/
import React, { Component } from "react";
import PageContent from "components/Elements/PageContent";
+const defaultState = { name: "", message: "" };
+
class ProfileForm extends Component {
constructor(props) {
super(props);
- this.state = {
- value: ""
- };
+ this.state = defaultState;
/* If we don't bind the event handler method,
* we'll get an error: "this" is undefined.
@@ -27,20 +27,26 @@ class ProfileForm extends Component {
this.handleSubmit = this.handleSubmit.bind(this);
}
- /* To be able to edit forms in React,
- * you'll need to handle changes.
+ /* To be able to edit forms in React,
+ * you'll need to handle changes.
* We'll create a function handleChange
*/
handleChange = event => {
- this.setState({ value: event.target.value });
+ const target = event.target;
+
+ this.setState({
+ [target.name]: target.value
+ });
};
/* Modify the function handleSubmit to log the form results.
- *
+ *
* You may also display the results in another component,
* maybe to the ProfileCard component? :)
*/
handleSubmit = event => {
+ console.log(this.state);
+ this.setState(defaultState);
event.preventDefault();
};
@@ -52,12 +58,22 @@ class ProfileForm extends Component {
>