gpt4 book ai didi

javascript - 不变违规 : Invariant Violation: Text strings must be rendered within a component

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:53:33 26 4
gpt4 key购买 nike

在 react-native 中创建一个应用程序遇到了这个问题。基本上我应该创建一个页面来打印当前登录到数据库(firebase)的用户的数据。我设法创建了一种排行榜,在另一页上打印所有用户的数据,但我无法弄清楚我错在哪里。有人可以帮助我吗?

https://snack.expo.io/@khal_d/proj-p-3

import React, { Component } from 'react';
import { View, TouchableOpacity, StyleSheet, Button, Text, ScrollView, ListItem } from 'react-native';
import { Input, Card} from 'react-native-elements';

import * as firebase from 'firebase';


export default class User extends Component {
static navigationOptions = {
title: 'UserInfo',
};

state = {
data: [],
};

// Controllare qui
componentDidMount(){
//leggere array dal db
const currentUID = firebase.auth().currentUser.uid;
const path ="/users/" + currentUID;
const users = firebase.database().ref(path);
users.on("value", snap => {
console.log("log di snap" + snap);
//ciclo
var elenco = [];
snap.forEach(child => {
elenco.push({
name: child.val().name,
surname: child.val().surname,
email: child.val().email,
image: child.val().image,
})
});

console.log("altro log finale" + elenco);
this.setState({data:elenco})
});

}

// controllare fino a qua

render() {

return (
<ScrollView>
<View>
<Card> //fix evertything all'interno di card
{
this.state.data.map((l, i) => (
<ListItem
key={i}
leftAvatar={{ source: { uri: l.image } }}
title={l.name}
subtitle={l.surname}

/>
))
}
</Card>
</View>
</ScrollView>
);
}
}

最佳答案

我认为问题出在评论上。在 JSX 中,用//注释不起作用。它将被视为文本。

您必须像下面这样更改您的评论,这将解决您的问题

    {/* fix evertything all'interno di card */}

关于javascript - 不变违规 : Invariant Violation: Text strings must be rendered within a <Text> component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54578486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com