我试图在react-native中创建一个菜单,它给了我这个错误,这是从JavaScript复制的代码,我想在tsx中传递它
错误: c:\ proyectosreactjs \ kapua \ src \ Screens \ Discover.tsx:c:/proyectosreactjs/kapua/src/Screens/Discover.tsx(39,13):';'预期的。
我不认为这是因为“;”如果不是,因为原始代码来自javaScript,我将其传递给typeScript
import React from 'react';
import {
StyleSheet,
Image,
Text,
View,
Dimensions,
TextInput,
TouchableOpacity,
TouchableWithoutFeedback,
} from 'react-native';
import { BackgroundGradient } from '../Components/BackgroundGradient';
import { List } from 'native-base';
import Icon from 'react-native-vector-icons/FontAwesome';
import Sidemenu from 'react-native-side-menu';
const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;
interface Props {
navigation: any;
}
interface State {}
export class Discover extends React.Component<Props, State> {
private images = [
{ image: require('../../assets/images/img0.jpg'), link: 'DetailScreen' },
{ image: require('../../assets/images/img1.jpg'), link: 'DetailScreen' },
{ image: require('../../assets/images/img2.jpg'), link: 'DetailScreen' },
{ image: require('../../assets/images/img3.jpg'), link: 'DetailScreen' },
{ image: require('../../assets/images/img4.jpg'), link: 'DetailScreen' }
];
constructor(props: Props) {
super(props);
this.state = {
isOpen: false
}
toggle(){
this.setState({
isOpen: !this.state.isOpen
})
}
;
}
updateMenu(isOpen){
this.setState({isOpen})
}
render() {
return (
<View style={styles.root}>
<Sidemenu
menu={}
isOpen={this.state.isOpen}
onChange={(isOpen) =>this.updateMenu(isOpen)}
>
<BackgroundGradient colors={['#142246', '#B634C5']} />
<View style={styles.header}>
<TouchableWithoutFeedback onPress={() => props.toggle()}>
<Icon
name="bars"
color="white"
size={30}
/>
</TouchableWithoutFeedback>
<Icon
name="search"
color="white"
size={30}
/>
</View>
<List
style={{ marginTop: 20 }}
dataArray={this.images}
renderRow={(data) => {
return (
<TouchableOpacity
onPress={() => {
this.props.navigation.navigate(data.link);
}}>
<Image
source={data.image}
style={{
width: width - 20,
height: 200,
alignSelf: 'center',
marginBottom: 20
}}
resizeMethod='resize'
resizeMode='contain'
/>
</TouchableOpacity>
);
}}
/>
</Sidemenu>
</View>
);
}
}
const styles = StyleSheet.create({
root: {
width: width,
height: height
},
header: {
width: width,
height: 60,
marginTop:30,
alignItems: 'center',
flexDirection: 'row',
justifyContent: 'space-between',
padding: 10,
//marginLeft: 10,
//marginRight: 10,
}
});
对英语很抱歉
答案 0 :(得分:0)
似乎constructor
在声明}
函数之前没有结束toggle
。
更改:
constructor(props: Props) {
super(props);
this.state = {
isOpen: false
}
toggle(){
this.setState({
isOpen: !this.state.isOpen
})
}
;
}
收件人:
constructor(props: Props) {
super(props);
this.state = {
isOpen: false
}
}
toggle() {
this.setState({
isOpen: !this.state.isOpen
});
}