Reputation: 3
In an event emitted from something like this:
function changed(ev) { /* ... */ }
<TextInput name='hello' onChange={changed} />
Is it possible to extract the name
prop from the event inside of changed()
?
function changed(ev) { console.log('name prop is', ev.???) }
and if so, is this stable across all events? The docs are not clear.
Upvotes: 0
Views: 1938
Reputation: 609
You can with refs, but I feel you are trying to work against the React Way(tm)...
inputChange(event) {
console.log('name', this._input.props.name);
}
render() {
return (
<TextInput name="hello" onChange={this.inputChange} ref={(c) => this._input = c}/>
);
}
You should have access to the 'name' prop from both inside the parent (after all its setting the value on the child) and from inside the child as part of its props values. So perhaps try to reevaluate on what you are trying to do :)
Upvotes: 2