【发布时间】:2018-11-28 00:29:41
【问题描述】:
我的 Main.js 文件中不断收到错误消息“对象不是函数...”。如何修复它以及我做错了什么?这是错误的屏幕截图:。这也是我的 Main.js 文件的代码:
import React from 'react';
import { StyleSheet, Text, Image, View, Vibrate } from 'react-native';
import Settings from './Settings';
import Profile from './Profile';
import {connect} from 'react-redux';
import {saveProfile, saveSettings} from '../redux/actions';
class Main extends React.Component {
componentWillMount() {
if (!this.props.avatarUrl) {
this.props.saveProfile(this.props.location);
}
}
render() {
return (
<View style={styles.container, bgColor}>
<Image
source={this.props.avatarUrl}
style={{width: 300, height: 300}}
/>
<Text>{this.props.name}</Text>
<Text>{this.props.phone}</Text>
<Text>{this.props.email}</Text>
<Settings />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default saveProfile (
connect(
state=>state.location,
{saveProfile}
)
)(Main);
我的目标是显示redux中保存的信息。
【问题讨论】:
-
你试过
connect( state=>state.location, {saveProfile} )(saveProfile (Main))吗? -
它给出了语法错误
SyntaxError: /Users/arina/Desktop/mobapp/comps/Main.js: Unexpected token, expected "," (47:20) -
在您的 connect(...) 中,请将
{saveProfile}替换为null。现在可以编译了吗? -
把里面的saveProfile也去掉,所以
export default connect( state=>state.location, null )(Main) -
在这种情况下,您可以省略第二个参数,而只需
connect( state=>state.location)(Main)
标签: reactjs react-native redux react-redux redux-thunk