【发布时间】:2019-11-03 07:29:45
【问题描述】:
我需要在我的应用程序中使用开关切换(库 git:dooboolab/react-native-switch-toggle)。我在 react-native 中使用打字稿。为 onPress 手势响应事件设置函数时出现错误。它说:类型 void 不能分配给布尔类型。
import React, {Component} from 'react';
import SwitchToggle form 'react-native-switch-toggle';
import {View} from 'react-native';
export default class Login extends Component{
state = {
switchOn : false
}
render(){
return (
<View>
<SwitchToggle
switchOn={this.state.switchOn}
onPress = {this.onPress1} //HERE THE ERROR
/>
</View>
)
}
onPress1 = () =>{
this.setState({switchOn:!this.state.switchOn});
}
}
我该如何解决?
【问题讨论】:
-
在onPress1函数上可以加一个return false;声明并尝试一下
-
还不行