我试图在 React 中访问 commercejs 库的公钥。但是我没有这样做并遇到了这个错误。我不明白为什么我会收到这个错误。
src\lib\commerce.js
import Commerce from '@chec/commerce.js';
export const commerce = new Commerce(process.env.REACT_APP_CHEC_PUBLIC_KEY, true);
src\App.js
import React, {useState, useEffect} from 'react';
import {Products, Navbar} from './components';
import {commerce} from './lib/commerce';
const App = () => {
const [products, setProducts] = useState([]);
const fetchProducts = async () => {
const {data} = await commerce.products.list();
setProducts(data);
}
useEffect(() => {
fetchProducts();
})
console.log(products);
return (
<div>
<Navbar/>
<Products/>
</div>
)
}
export default App;
错误
TypeError: t is undefined e node_modules/@chec/commerce.js/lib/index.js:1