小编Eri*_*man的帖子

通过路线中的高阶组件传递道具

我的高阶组件有问题.我试图从<Layout />路由中的组件传递道具(React Router v4).路由中指定的组件由HOC包装,但我传递的道具永远不会到达组件.

另外,我不能在不使用的情况下使用HOC export default () => MyHOC(MyComponent).我无法弄清楚为什么,但这可能与它有关?

Layout.js

const Layout = ({ location, initialData, routeData, authenticateUser }) => (
  <Wrapper>
    <Container>
        <Switch>
          // how do I get these props passed through the HOC? render instead of component made no difference.
          <Route exact path="/pages/page-one" component={() => <PageOne routeData={routeData} title="PageOne" />} />
          <Route exact path="/pages/page-two" component={() => <PageTwo routeData={routeData} title="PageTwo" />} />
          <Route component={NotFound} />
        </Switch>
    </Container>
  </Wrapper>
)

export default Layout
Run Code Online (Sandbox Code Playgroud)

Page.js

// I've tried …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-router react-router-v4

10
推荐指数
1
解决办法
9671
查看次数