Skip to content

Instantly share code, notes, and snippets.

View suzdalnitski's full-sized avatar

Ilya Suzdalnitskiy suzdalnitski

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