无法从渲染器中调用函数。我的部分是:渲染器中的调用函数无法正常工作
class MyComp extends Component {
componentWillMount() {
this.props.getUsers();
};
getUsersfunction(users){
return(
console.log("i was called");
users.map((user, idx) => {
return (
<View key={idx}>
<Text style={styles.userNames}> ID: {user.id} - Name: {user.name} </Text>
</View>
)
});
)
};
render() {
console.log("USERS: ", this.props.users);
const { users } = this.props.users
return (
<View style={styles.container}>
<ScrollView>
{ users.length ? (
{this.getUsersfunction(users)} // <= Is this the correct way?
) : null }
</ScrollView>
</View>
);
}
}
// mapStatetoProps and mapDispatchToProps here.
export default connect(mapStateToProps, mapDispatchToProps) (MyComp);
错误是this
是一个保留字。 Console.log播放数组中的所有用户。我究竟做错了什么?
'getUsersfunction'目前不返回任何东西。你可能想要添加一个return语句。 – Brian
已更新的问题。这是我的错误。原始代码有回报。仍然没有返回。但控制台日志'“我被称为”' – Somename