我开始学习React JS,所以我m trying to build an app that makes cotation and I
m试图将cotation值作为prop传递。
但是它不起作用,请帮帮忙!
谢谢!
import './App.css';
import RealDolar from './components/real_dolar.js';
function App() {
let realDolar = 0;
let url = 'https://api.freecurrencyapi.com/v1/latest?base_currency=USD¤cies=BRL&apikey=xyz';
fetch(url).then(res=>{
return res.json()
}).then(json=>{
realDolar = json['data']['BRL'];
})
return (
<div className="Real_Rapido">
<RealDolar cotacao={realDolar} />
</div>
);
}
export default App;
2条答案
按热度按时间rsl1atfo1#
您好!您需要使用
useState
和useEffect
钩子。了解更多关于hooks的信息:https://react.dev/reference/react/useState和https://react.dev/reference/react/useEffect
wvyml7n52#
传递的prop应该是一个state: