我想在另一个组件的范围内获得投资变量......
我已经编写了下面的代码,这没问题,但是由于我已经导出了函数 InvestmentsList,我怎样才能获得这个 const 投资?如果不使用 react-redux 中的 useSelector() 怎么办?
import React, { useEffect, useState } from 'react';
import {
Card,CardBody,CardHeader,CardTitle,Col,Row,Table} from 'reactstrap';
import moment from 'moment';
const InvestmentsList = () => {
const [investment, setInvestment] = useState([]);
async function fetchInvestments() {
const response = await fetch('http://localhost:3000/products');
const investments = await response.json();
// waits until the request completes...
setInvestment(investments);
}
useEffect(() => {
fetchInvestments();
}, []);
return (
<>{/* ...Returns something */}</>)
export default InvestmentsList;