无法在React yahoo Finance 2包中运行代码

问题描述 投票:0回答:1

我正在使用 Vite 构建一个 React(

tsx
) 应用程序。我的应用程序使用 yahoo-finance2 包从雅虎获取股票相关信息。

当我作为独立的 js 文件运行时,它按预期工作。但是,当我在反应中使用相同的内容时,我收到一个错误“Uncaught ReferenceError:进程未定义”。这是我的代码。 import { useEffect, useState } from "react"; import "./index.css"; import yahooFinance from "yahoo-finance2"; function App() { const [isLoading, setIsLoading] = useState(false); useEffect(() => { const getQuote = async () => { setIsLoading(true); try { const response = await yahooFinance.quote("TSLA"); console.log(response); } catch (err) { console.error(err); } setIsLoading(false); }; getQuote(); }, []); return ( <div className="flex w-full h-screen justify-center items-center"> <div className="text-lg">{isLoading ? `Loading...` : `Hello world!`}</div> </div> ); } export default App;

有人可以让我知道我哪里出错了吗? 
这里

是我的仓库,如果有帮助的话。 谢谢!

reactjs node.js typescript yahoo-finance
1个回答
0
投票

async function updateExchangeRate() { fetch('https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=IBM&interval=5min&apikey=demo') .then((response) => { return response.json() }) .then((data) => { console.log(data) }) }

立即获取 apikey(替换上面网址中的“demo”)非常简单。

© www.soinside.com 2019 - 2024. All rights reserved.