I'm facing an issue trying to render a class variable.
import Api from '../services/Api';
class Boxify extends Component {
constructor(props) {
super(props);
}
async componentWillMount() {
this.response = await Api.getUserCurrent();
this.mail = this.response.data.email;
alert(this.mail);
}
render() {
return (
<View>
<Text>
{this.mail}
</Text>
</View>
)
}
}
export default Boxify;
What I can't figure out is why does the alert in the componentWillMount shows me the email_adress, and the render doesn't show anything ?
this.mailis undefined. And since you aren't callingsetState()/ usingthis.statelike you're supposed to,render()isn't called again. Either makemailpart of the component's state, or force a re-rendering.