我已经创建了以下更高阶的组件,从React中导入React,{useEffect}
export const withCall = (WrappedComponent, calllName) => {
const HOC = () => {
useEffect(() =>{report(calllName)}, [])
return <WrappedComponent />
}
return HOC
}
和这条路线:
<Route exact path={pagePath/:someId} component={withCall(ContainerComponent, 'any_call_name')} />
在ContainerComponent中,我正在尝试访问this.props.match.params
...只要我不在(<Route exact path={pagePath/:someId} component={ContainerComponent} />
)之间使用HoC,我就具有这些属性,但是当我使用它时,我将无法再访问它们。如何在保持高阶组件通用的同时将它们传递给它?
尝试一下:
const HOC = (props) => {
useEffect(() =>{report(calllName)}, [])
return <WrappedComponent {...props} />
}