admin管理员组文章数量:1400174
So im trying to wrap my head around react native and it does not look difficult.
My question is straight forward, what is the "e" object how do I use its properties such as "e.nativeEvent" and "e.nativeEvent.text", and in what situations?
I stumbled upon this object when I was testing TextInput's onChangeText and onBlur props.
As you can see below, I am able to pass an argument parameter called "value" in the onChangeText prop, to the callback handler. BUT when I tried to do the same with the onBlur, I ran into issues ( and I checked the documentation which did not mention anything about an argument being passed to the callback function handler, unlike the onChangeText).
So I found this question, which helped me figure out how to access the data in TextInput using the e.eventNative.text property.
render(){
return(
<View>
<Text>indent</Text>
<Text>indent</Text>
<TextInput
style={{height:60, backgroundColor: "#ededed"}} // must define a height for T.I in iOS
placeholder="Enter Text"
value={this.state.textValue}
onChangeText={(value) => this.onChangeText(value)}
/>
<Text>{this.state.textValue}</Text>
{/* on submit editing, will find the callback function to transfer text
when submitting button is pressed */}
<TextInput
style={{height:60, backgroundColor: "skyblue"}}
placeholder="Enter Text"
onBlur={(value) => this.onSubmit(value.nativeEvent.text)}
/>
<Text>{this.state.textSubmitted}</Text>
</View>
);
} }
So im trying to wrap my head around react native and it does not look difficult.
My question is straight forward, what is the "e" object how do I use its properties such as "e.nativeEvent" and "e.nativeEvent.text", and in what situations?
I stumbled upon this object when I was testing TextInput's onChangeText and onBlur props.
As you can see below, I am able to pass an argument parameter called "value" in the onChangeText prop, to the callback handler. BUT when I tried to do the same with the onBlur, I ran into issues ( and I checked the documentation which did not mention anything about an argument being passed to the callback function handler, unlike the onChangeText).
So I found this question, which helped me figure out how to access the data in TextInput using the e.eventNative.text property.
render(){
return(
<View>
<Text>indent</Text>
<Text>indent</Text>
<TextInput
style={{height:60, backgroundColor: "#ededed"}} // must define a height for T.I in iOS
placeholder="Enter Text"
value={this.state.textValue}
onChangeText={(value) => this.onChangeText(value)}
/>
<Text>{this.state.textValue}</Text>
{/* on submit editing, will find the callback function to transfer text
when submitting button is pressed */}
<TextInput
style={{height:60, backgroundColor: "skyblue"}}
placeholder="Enter Text"
onBlur={(value) => this.onSubmit(value.nativeEvent.text)}
/>
<Text>{this.state.textSubmitted}</Text>
</View>
);
} }
Share Improve this question asked Jun 15, 2017 at 15:45 user3676224user3676224 8732 gold badges12 silver badges25 bronze badges 3- 1 this explains it pretty well stackoverflow./a/40092220/3473220 – Garrett McCullough Commented Jun 15, 2017 at 16:40
- 1 not the best explanation, but appreciated, thanks. – user3676224 Commented Jun 21, 2017 at 13:48
-
1
I've been asking the same question since beginning with React Native, and it seems like at this time there is no official documentation for what the various
on*
callbacks receive. – Mark Commented Jun 2, 2018 at 18:32
1 Answer
Reset to default 1onChangeText is a special event for TextInputs whose handler is passed the text of the TextInput as the initial argument (so 'value' = 'ev.nativeEvent.value' for other events).
The onBlur event doesn't have this feature. So you'll need to access the text of the TextInput like you are.
本文标签: javascriptreact nativenativeEvent propertyStack Overflow
版权声明:本文标题:javascript - react native - nativeEvent property? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744191501a2594539.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论