Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save manoelneto/871540c820ef20170b350c5345f23452 to your computer and use it in GitHub Desktop.
Save manoelneto/871540c820ef20170b350c5345f23452 to your computer and use it in GitHub Desktop.
class ComponentThatsGenerateAValue extends Component {
state = {
value: initialState
}
onChange = newState => {
this.setState({value: newState})
}
render() {
return createElement(
this.props.component,
{
value: this.state.value,
onChange: this.onChange
}
)
}
}
class ComponentThatRenders extends Component {
render() {
return <input value={this.props.value} onChange={evt => this.props.onChange(evt.target.value)} />
}
}
// or
const ComponentThatRenders = (props) => {
return <input value={props.value} onChange={evt => props.onChange(evt.target.value)} />
}
<ComponentThatsGenerateAValue
component={ComponentThatRenders}
></ComponentThatsGenerateAValue>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment