Javascript 文本标记内的函数React Native

Javascript 文本标记内的函数React Native,javascript,react-native,Javascript,React Native,我对react native Text标记有问题。我不明白为什么会这样。请帮帮我。 我需要在文本标记中使用函数retrieveData,但这会产生错误。我做错了什么?谢谢 我已经在另一个文件中使用异步存储设置了数据(mobileNumber作为密钥) import React, { Component } from "react"; import { View, Text, TextInput, SafeAreaView, TouchableOpacity, AsyncS

我对react native Text标记有问题。我不明白为什么会这样。请帮帮我。 我需要在文本标记中使用函数retrieveData,但这会产生错误。我做错了什么?谢谢 我已经在另一个文件中使用异步存储设置了数据(mobileNumber作为密钥)

import React, { Component } from "react";
import {
  View,
  Text,
  TextInput,
  SafeAreaView,
  TouchableOpacity,
  AsyncStorage
} from "react-native";

export default class PhoneCode extends Component {
  constructor(props) {
    super(props);
    this.state = {
    };
  }
  onVerify = () => {};
  onPress = () => {
    alert("Sending...");
  };
  tappedVerify = () => {
    console.log("clicked")
  };
  render() {
    const { code, isCodeValid } = this.state;
    const _retrieveData = async () => {
      try {
        const value = await AsyncStorage.getItem("mobileNumber");
        if (value !== null) {
          // We have data!!
          return value;
        }
      } catch (error) {
        // Error retrieving data
        console.log("failed");
      }
    };
    return (
      <SafeAreaView style={styles.container}>
        <View style={styles.contentArea}>
          <Text style={{}}> Enter... </Text>

          <View style={styles.codeArea}>
            <Text style={styles.codeInput}> {_retrieveData()} </Text> // this is the problem

            <TextInput
              placeholder="Enter here"
              underlineColorAndroid="transparent"
              style={styles.textInput}
              maxLength={6}
              autoGrow={true}
              maxHeight={40}
              keyboardType={"phone-pad"}
              onChangeText={(text) =>
                this.setState({
                  //....
                })
              }
            />
          </View>
       </View>
      </SafeAreaView>
这是错误消息

ExceptionsManager.js:74 Invariant Violation: Objects are not valid as a React child (found: object with keys {_40, _65, _55, _72}). If you meant to render a collection of children, use an array instead.

这样做解决了我的问题。它可能会帮助其他人

<Text style={styles.codeInput}> {`${_retrieveData()}`} </Text>
{${u retrieveData()}}}
<Text style={styles.codeInput}> {`${_retrieveData()}`} </Text>