【发布时间】:2020-01-28 15:44:23
【问题描述】:
在使用 NativeBase 为 Android 开发 React Native 应用程序时,我遇到了一个问题。尽管使用了箭头函数,但我的 Button 组件中的 onClick() 事件没有触发,我不知道为什么。
代码如下:
import React from 'react';
import {View, Text} from 'react-native';
import {withNavigation} from 'react-navigation';
import {Button, Header, Icon, Item, Input} from 'native-base';
let text = '';
class SearchBar extends React.Component {
onButtonClick = () => {
text = 'yes';
};
render() {
return (
<View>
<Header searchBar rounded>
<Item>
<Icon name="ios-search" />
<Input placeholder="Search" />
</Item>
</Header>
<Button onClick={() => this.onButtonClick()}>
<Text>Search</Text>
</Button>
<Text>Is the button clicked? {text}</Text>
</View>
);
}
}
export default withNavigation(SearchBar);
你能帮帮我吗?在所有其他组件中,我实现了与上面示例完全相同的事件功能,并且这些功能正在运行。上面那个有什么问题?
我还尝试了来自 React-Native 而不是 NativeBase 的 Button - 同样的问题。
【问题讨论】: