React Native with Node.js后端中出错
我收到的错误: 应用程序屏幕上没有显示任何内容,但当我登录控制台时,它正在从终端中的服务器获取数据 应用程序屏幕feedscreen.jsReact Native with Node.js后端中出错,node.js,mongodb,react-native,Node.js,Mongodb,React Native,我收到的错误: 应用程序屏幕上没有显示任何内容,但当我登录控制台时,它正在从终端中的服务器获取数据 应用程序屏幕feedscreen.js import React, {useEffect, useState} from 'react'; import {ActivityIndicator, Text, View, FlatList} from 'react-native'; import stylesheet from '../src/styles/HomeStyle'; import Asy
import React, {useEffect, useState} from 'react';
import {ActivityIndicator, Text, View, FlatList} from 'react-native';
import stylesheet from '../src/styles/HomeStyle';
import AsyncStorage from '@react-native-community/async-storage';
const FeedScreen = props => {
const [text, setText] = useState('loading');
const Boiler = async () => {
const token = await AsyncStorage.getItem('token');
fetch('http://192.168.*.*:3000/post', {
headers: new Headers({
Authorization: 'Bearer ' + token,
}),
})
.then(res => res.json())
.then(data => {
console.log(data);
setText(data.text);
});
};
useEffect(() => {
Boiler();
}, []);
return (
<View style={stylesheet.container}>
<Text>{text}</Text>
</View>
);
};
export default FeedScreen;
您的
数据似乎是一个数组,请尝试调用setText(数据[0].text)
但这只能返回一个数据yyes,如果要显示所有数据,可以使用FlatList。如果数据
是一个数组,请尝试调用setText(数据[0].text)代码>但这只能返回一个数据。如果要显示所有数据,可以使用FlatList
LOG Running "AwesomeProject" with {"rootTag":61,"initialProps":{}}
LOG {"email": "test@demo.com", "name": "test demo"}
LOG [{"_id": "5e436d9112911336750a9fa6", "slug": "this-is-node-express-and-mongodb", "text": "This is node express and mongodb.", "user": [[Object]]}, {"_id": "5e3a976d5ca38b812a93d5fa", "slug": "this-is-the-social-network-api-which-is-build-on-top-of-node-express-and-mongodb", "text": "This is the social network api which is build on top of node express and mongodb.", "user": [[Object]]}, {"_id": "5e3a975d5ca38b812a93d5f9", "slug": "this-is-the-social-network-api-which-is-build-on-top-of-node-express-and-mongodb", "text": "This is the social network api which is build on top of node express and mongodb.", "user": [[Object]]}]