Skip to content

Instantly share code, notes, and snippets.

@muhammadghazali
Last active July 11, 2018 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muhammadghazali/2269de49fba26b12df53eb5ef3474074 to your computer and use it in GitHub Desktop.
Save muhammadghazali/2269de49fba26b12df53eb5ef3474074 to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
class App extends Component {
constructor() {
super();
this.state = {
input1: ""
};
this.handleChange = this.handleChange.bind(this);
}
handleChange() {
this.setState({ input1: this.refs.input1.value });
}
render() {
return (
<div>
<h1>{this.state.text}</h1>
<InputWidget update={this.handleChange} />{" "}
<span>{this.state.input1}</span>
</div>
);
}
}
const InputWidget = props => (
<input ref="input" onDoubleClick={props.update} onChange={props.update} />
);
export default App;
import React, { Component } from "react";
class App extends Component {
constructor() {
super();
this.state = {
input1: "",
input2: ""
};
this.handleChange = this.handleChange.bind(this);
}
handleChange() {
this.setState({
input1: this.input1.refs.input.value,
input2: this.input2.refs.input.value
});
}
render() {
return (
<div>
<h1>{this.state.text}</h1>
<InputWidget
ref={component => (this.input1 = component)}
update={this.handleChange}
/>{" "}
<span>{this.state.input1}</span>
<InputWidget
ref={component => (this.input2 = component)}
update={this.handleChange}
/>{" "}
<span>{this.state.input2}</span>
</div>
);
}
}
class InputWidget extends Component {
render() {
return (
<input
ref="input"
onDoubleClick={this.props.update}
onChange={this.props.update}
/>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment