0
The error appears in this.converter = this.converter.bind(this);
My script:
import React, { Component } from 'react'
export default class conversor extends Component {
constructor(props){
super(props);
this.state = {
moedaA_valor: "",
moedaB_valor: 0,
}
}
this.converter = this.converter.bind(this);
converter(){
let de_para = `${this.props.moedaA}_${this.props.moedaB}`;
let url = `https://api.currconv.com/api/v7/convert?q=${de_para}&compact`
fetch(url)
.then(res=>{
return res.json()
})
.then(json=>{
let cotacao = json[de_para].val;
let moedaB_valor = ( parseFloat (this.state.moedaA_valor) * cotacao).toFixed(2)
this.setState({moedaB_valor})
})
}
render() {
return(
<div className="conversor">
<h2>{this.props.moedaA} para {this.props.moedaB}</h2>
<input type="text" onChange={(event)=>(this.setState({moedaA_valor:event.target.value}))}></input>
<input type="button" onClick= {this.converter} value="Converter"></input>
<h2>{this.state.moedaB_valor}</h2>
</div>
)
}
}
Pedro, can you edit with the full code of your class? Furthermore, I think it is pq vc can not put commands in the middle of the class, the commands must exist inside a method.
– Allan Juan