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
// style.js: | |
const style = { | |
form: { | |
margin: 50, | |
padding: 10, | |
width: 300, | |
border: "1px solid black", | |
backgroundColor: "black", | |
color: "white" | |
}, |
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
render() { | |
const { firstNameError, firstName } = this.state; | |
return ( | |
<div | |
style={{ | |
margin: 50, | |
padding: 10, | |
width: 300, | |
border: "1px solid black", |
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
class SimpleForm extends React.Component { | |
state = { | |
firstName: "", | |
firstNameError: "", | |
}; | |
validateName = name => { | |
const regex = /[A-Za-z]{3,}/; | |
return !regex.test(name) |
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
class SimpleForm extends React.Component { | |
state = { | |
firstName: "", | |
lastName: "" | |
}; | |
onFirstNameChange = event => | |
this.setState({ | |
firstName: event.target.value | |
}); |
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
class SimpleForm extends React.Component { | |
state = { | |
firstName: "", | |
}; | |
onFirstNameChange = event => | |
this.setState({ | |
firstName: event.target.value | |
}); |
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 SimpleForm extends React.Component { | |
render() { | |
return ( | |
<div> | |
<input type="text" name="firstName" /> | |
<Greetings firstName="John" /> | |
</div> | |
); |
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
class Greetings extends React.Component { | |
render() { | |
return ( | |
<div>Hey you! {this.props.firstName} {this.props.lastName}!</div> | |
); | |
} | |
} |
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
const Greetings = ({ firstName, lastName }) => <div>Hey you! {firstName} {lastName}!</div>; |
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
const Greetings = (props) => <div>Hey you! {props.firstName} {props.lastName}!</div>; | |
const App = () => ( | |
<div> | |
<Greetings firstName="John" lastName="Smith" /> | |
</div> | |
); |
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
const App = () => ( | |
<div className="App"> | |
... | |
</div> | |
); | |
export default App; |