I have a long list of financial data stored in a JS File:
{
StockId: 0,
link: "/Stock-detail",
StockName: "Wayne Enterprises",
StockPrice: "81.58 CHF",
StockChange: "-3%",
StockCategory: 'Real Estate'
StockMarketCap: "909T",
StockMarketVolume: "853T",
StockTrend: "pos",
StockPriceChart: TrendPos,
StockMinInvest: "500,00 CHF",
StockRegulators: "FINMA",
How can I pass / filter only a specific subset of this data, for example only those entries with the Stock Category 'Real Estate' , into a component? This is how data is currently passed:
Stock.map(item => {
return (
<StockTile
StockName={item.StockName}
StockType={item.StockType}
StockCategory:{item.StockCategory}
StockPrice={item.StockPrice}
link={item.link}
StockTrend={item.StockTrend}
StockPriceChart={item.StockPriceChart}
/>
)
})
}
Try this:
Stock.filter(item => item.StockCategory === "Real Estate").map(item => {
return (
<StockTile
StockName={item.StockName}
StockType={item.StockType}
StockCategory={item.StockCategory}
StockPrice={item.StockPrice}
link={item.link}
StockTrend={item.StockTrend}
StockPriceChart={item.StockPriceChart}
/>
);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.