【发布时间】:2021-01-31 22:09:03
【问题描述】:
我有这条路线调用PriceWithId 函数
<Route path='/collections/:pId' component={PriceWithID} />
函数是这样的
const PriceWithID = ({match}) =>
{
let test = Object.entries(match);
let test2 = test.filter(([prop])=>(prop === 'params'));
let test3 = test2[0][1];
let test4 = Object.values(test3)[0]
return(
<Price image={IMGS.filter((i)=>(i.id === parseInt(test4,10)))[0]}/>
);
}
我知道有一种更好的单线方式来实现test4。我使用的方法经过反复试验。谁能告诉我更好的方法,以便我可以用它替换 parseInt 中的 test4
【问题讨论】:
标签: javascript html reactjs react-router react-router-dom