pull/64/head
asabeneh 5 years ago
parent 626a9758e3
commit 3f444666e4

@ -106,7 +106,11 @@ class App extends Component {
} }
render() { render() {
// accessing the state value and this value will injected to the input in the value attribute /*
accessing the state value and
this value will injected to the input in the value attribute
*/
const firstName = this.state.firstName const firstName = this.state.firstName
return ( return (
<div className='App'> <div className='App'>
@ -139,7 +143,7 @@ In this section we will develop a small form which collect user information. Our
import React, { Component } from 'react' import React, { Component } from 'react'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
class App extends Component { class App extends Component {
// declaring state // declaring initial state
state = { state = {
firstName: '', firstName: '',
lastName: '', lastName: '',
@ -159,7 +163,6 @@ class App extends Component {
this.setState({ [name]: value }) this.setState({ [name]: value })
} }
handleSubmit = (e) => { handleSubmit = (e) => {
/* /*
e.preventDefault() e.preventDefault()
stops the default behavior of form element stops the default behavior of form element
@ -290,12 +293,15 @@ class App extends React.Component {
} }
handleChange = (e) => { handleChange = (e) => {
/* /*
// we can get the name and value like this but we can also destructure it from e.target we can get the name and value like: e.target.name, e.target.value
Wwe can also destructure name and value from e.target
const name = e.target.name const name = e.target.name
const value = e.target.value const value = e.target.value
*/ */
const { name, value, type, checked } = e.target const { name, value, type, checked } = e.target
// [variablename] this we can make a value stored in a certain variable could be a key for an object, in this case a key for the state /*
[variablename] we can make a value stored in a certain variable could be a key for an object, in this case a key for the state
*/
if (type === 'checkbox') { if (type === 'checkbox') {
this.setState({ this.setState({
@ -309,7 +315,11 @@ class App extends React.Component {
} }
} }
handleSubmit = (e) => { handleSubmit = (e) => {
// stops the default behavior of form element specifically refreshing of page /*
e.preventDefault()
stops the default behavior of form element
specifically refreshing of page
*/
e.preventDefault() e.preventDefault()
const { const {
firstName, firstName,
@ -347,7 +357,10 @@ class App extends React.Component {
file, file,
skills: formattedSkills, skills: formattedSkills,
} }
// the is the place where we connect backend api to send the data to the database /*
the is the place where we connect backend api
to send the data to the database
*/
console.log(data) console.log(data)
} }
@ -624,12 +637,15 @@ class App extends Component {
} }
handleChange = (e) => { handleChange = (e) => {
/* /*
// we can get the name and value like this but we can also destructure it from e.target we can get the name and value like: e.target.name, e.target.value
Wwe can also destructure name and value from e.target
const name = e.target.name const name = e.target.name
const value = e.target.value const value = e.target.value
*/ */
const { name, value, type, checked } = e.target const { name, value, type, checked } = e.target
// [variablename] this we can make a value stored in a certain variable could be a key for an object, in this case a key for the state /*
[variablename] we can make a value stored in a certain variable could be a key for an object, in this case a key for the state
*/
if (type === 'checkbox') { if (type === 'checkbox') {
this.setState({ this.setState({
@ -660,7 +676,11 @@ class App extends Component {
return errors return errors
} }
handleSubmit = (e) => { handleSubmit = (e) => {
// stops the default behavior of form element specifically refreshing of page /*
e.preventDefault()
stops the default behavior of form element
specifically refreshing of page
*/
e.preventDefault() e.preventDefault()
const { const {
@ -699,7 +719,10 @@ class App extends Component {
file, file,
skills: formattedSkills, skills: formattedSkills,
} }
// the is the place where we connect backend api to send the data to the database /*
the is the place where we connect backend api
to send the data to the database
*/
console.log(data) console.log(data)
} }

Loading…
Cancel
Save