I have the code:
import React, { Component } from 'react';
import { ScrollView } from 'react-native';
import { Tile, List, ListItem } from 'react-native-elements';
class UserDetail extends Component {
constructor(props){
super(props);
this.state = {
title: '',
phone: '',
}
}
render() {
const { id, title, whatsapp, email, phone, login, location } = this.props.navigation.state.params;
//RECEBO A CONSTANTE ACIMA DA TELA ANTERIOR. ALGUNS ITENS VEM COM INFORMAÇÃO, OUTROS NÃO
if (title){
this.setState({title: {title}});
}
if (phone){
this.setState({phone: {phone}});
//QUERO SABER SE A CONSTANTE ACIMA TEM INFORMAÇÃO, E ASSIM, USÁ-LA NO ESTADO CORRESPONDENTE, POIS QUANDO ESTÁ VAZIA DÁ ERRO
}
return (
<ScrollView>
<Tile
imageSrc={{ uri: 'https://buscafree.com.br/assets/img/items/${id}.jpg'}}
featured
title={title}
//caption={email}
/>
<List>
<ListItem
title="Endereço"
rightTitle={this.state.title}
hideChevron
/>
<ListItem
title="Endereço"
rightTitle={this.state.phone} //USAREI AQUI
hideChevron
/>
</List>
</ScrollView>
);
}
}
export default UserDetail;
My code receives some information from the previous screen. However, not all items have a value (in my case, the PHONE item sometimes comes with information and sometimes not ...)
When I try to print it on the screen, it gives an error if it is empty / null.
How do I check if it has information before printing on the screen?