I have the following code:
state = {
name: 'Teste II',
produto: null,
alternativas: null,
loading_produto: true,
loading_alternativas: true,
showPopup: false,
};
constructor( props ) {
super( props );
}
async componentDidMount(){
const url = "http://www.mocky.io/v2/5db857da3b0000770035f09b";
const response = await fetch(url);
const data = await response.json();
this.setState({produto: data.suggestions[0], loading_produto: false})
this.setState({alternativas: data.choices, loading_alternativas: false})
console.log(this.state.produto.product_data.title);
}
render() {
const lista = this.state.alternativas;
if(!this.state.loading_alternativas){
this.texts = lista.map((text, key) => {
console.log('chegou aqui');
<li key={text.id}>{text.name}</li>
});
}
return (...<ul>{this.texts}</ul>... )
It seems okay for me. Indeed, the code "console.log('chegou aqui');" is being executed. However the command "
- {this.texts}
What is the problem?
Note that the API is being simulated by the link: API