I just started coding in JS to make a website for my script, yet I'm having some noob issues.
I'm updating variables via an async await function connected to a fetch function. I want to render my variables in another script, and doing so has resulted in quiet the headache.
Here's what I have so far, but it seems like the second file is importing nul variables.
This is my computing and variable declaring file:
var url = 'https://financialmodelingprep.com/api/v3/profile/'+tickersymb+'?apikey='+api
var priceStat = "Working..."
var jsonData
function checkStats(url, callback) {
return fetch(url)
.then((response) => {
return response.json().then((data) => {
console.log(data);
return data;
}).catch((err) => {
console.log(err);
})
});
}
(async () => {
jsonData = await checkStats(url)
priceStat = jsonData.[0].price
exports.jsonData = jsonData
exports.priceStat = priceStat
exports.tickersymb = tickersymb
})();
This is my rendering script:
var compute = require('components/compute-engine');
var pricestat = compute.pricestat;
var tickersymb = compute.tickersymb;
var jsonData = compute.jsonData;
export default function HeaderStats() {
return (
<>
{/* Header */}
<div className="relative bg-blue-600 md:pt-32 pb-32 pt-12">
<div className="px-4 md:px-10 mx-auto w-full">
<div>
{/* Card stats */}
<div className="flex flex-wrap">
<div className="w-full lg:w-6/12 xl:w-3/12 px-4">
<CardStats
statSubtitle=""
ticker= {tickersymb}
exchange="NASDAQ"
statIconName="fas fa-dollar-sign"
statIconColor="bg-green-500"
/>
...