在遇到此问题的 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/

10-11 03:52