Skip to content

Instantly share code, notes, and snippets.

@flavioribeirojr
Last active October 30, 2018 13:51
Show Gist options
  • Save flavioribeirojr/377723c138599029bebfc60b05aaf49c to your computer and use it in GitHub Desktop.
Save flavioribeirojr/377723c138599029bebfc60b05aaf49c to your computer and use it in GitHub Desktop.
Exemplo fluxo pai > filho de formulário
import React, { Component } from 'react'
import ReactDOM from "react-dom";
class Input extends Component {
render() {
return (
<div>
<h2>Filho: {this.props.value}</h2>
<input
name={this.props.name}
value={this.props.value}
onChange={(e) => this.props.onChange(e.target.value)}
/>
</div>
)
}
}
class Form extends Component {
constructor(props) {
super(props)
this.state = {
name: 'test',
email: '[email protected]'
}
}
render() {
return (
<div>
<p>Name: {this.state.name}</p>
<Input name="name" value={this.state.name} onChange={(value) => this.setState({name: value})} />
<Input name="email" value={this.state.email} onChange={(value) => this.setState({email: value})} />
</div>
)
}
}
const App = () => <Form />
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment