Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6215

Why does the string come as an object React Native?

$
0
0

I draw a string value through api and I want to print it in View. But the incoming string value comes as Promise. How can I prevent this?

"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."

async getTitle(id) {            try {        const username = await AsyncStorage.getItem('username');        const token = await AsyncStorage.getItem('token');                    if(token) {            var credentials = Base64.btoa(username +':'+ token);            var URL         = `https://portal.xxxxx.com/api/v1/User/${id}`;            var title = await axios.get(URL, {headers : { 'Espo-Authorization' : credentials }})            .then((res) => {                return <Text>{res.data.title}</Text>            })            .catch((err) => {                console.log(err);            });            return title;        }    }catch (err) {        console.log(err);    }}<List    contentContainerStyle={styles.listContentContainer}    data={stream}    ItemSeparatorComponent={Divider}    renderItem={({ item, index }) => (        item.type === "Post" ?<ListItem            key={index}            title={<Text><Text style={{ fontSize: 12 }}>{item.createdByName}</Text> {this.getTitle(item.createdById)} {'\n'} <Text style={{ fontSize: 12 }}>{Moment(item.createdAt).add(3, 'hours').format('lll')}</Text>{'\n'}<Text style={{ fontSize: 12 }} status="warning">{this.statusLanguage(status)}</Text></Text>}            description={<Text style={{ fontSize: 15 }}>{item.post}</Text>}            accessoryLeft={renderCommentIcon}        /> : null    )}/>

Viewing all articles
Browse latest Browse all 6215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>