-1
How do I search for information within the api and display on the screen? It seems that the React does not recognize my function fetch
import React, { Component } from 'react'
class InputeAPI extends Component{
constructor(){
super()
this.state={valor:'Seach for a country', buscaapi:[]}
//agora consumiremos a API
var isto=fetch('https://restcountries.eu/rest/v2/all').then(f=>f.json()).then(funcaoapi=>{console.log(funcaoapi)})
this.consumir=this.consumir.bind(this)
}
consumir(){
window.alert(this.state.valor)
this.setState({buscaapi:this.funcaoapi})
console.log(this.state.buscaapi)
}
render(){
return(
<div>
<input id='inpu' onChange={(estado)=>this.setState({valor:estado.target.value})} type="text"value={this.state.valor}/>
<button onClick={this.consumir}> procurar</button>
</div>
)
}
}
export default InputeAPI