Created
July 15, 2020 18:26
-
-
Save humphd/a1f6eb671973264fbc86c45b77e43a00 to your computer and use it in GitHub Desktop.
Test 3, Question 2: Clarifying React state vs. props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Email from './Email'; | |
class App extends React.Component() { | |
constructor() { | |
super(); | |
this.state = { | |
name: 'First Last', | |
email: '[email protected]', | |
}; | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<h1>Email App</h1> | |
<Email author={this.state.email} /> | |
</div> | |
); | |
} | |
} | |
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
class Email extends React.Component() { | |
constructor(props) { | |
super(props); | |
this.state = { | |
subject: '', | |
message: '' | |
}; | |
} | |
render() { | |
return ( | |
<form> | |
<label> | |
Author: | |
<input type="email" name="author" value={this.props.author} /> | |
</label> | |
<label> | |
Author: | |
<input type="text" name="subject" value={this.state.subject} /> | |
</label> | |
<label> | |
Message: | |
<textarea>{this.state.message}</textarea> | |
</label> | |
</form> | |
); | |
}; | |
} | |
export default Email; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment