React-router和jsx-no-bind

时间:2017-07-11 19:06:25

标签: react-router react-jsx jsx

我正在使用react-router进行导航。我有一些组件需要登录才能看到它们。

因此我有这个:(来自react-router中的以下文档)

<Route
  {...rest}
  render={props =>
    isLoggedIn()
      ? <Component {...props} />
      : <Redirect
          to={{
            pathname: '/login',
            state: {from: props.location},
          }}
        />}
/>

然而,这有一个问题,因为jsx-no-bind不允许箭头功能。这是正确的方法是什么?或者这应该被忽略,因为它由于某种原因没有遭受相同的性能命中?

1 个答案:

答案 0 :(得分:0)

关于渲染道具的官方React文档:

https://reactjs.org/docs/render-props.html

本文档使用以下示例:

<DataProvider render={data => ( <h1>Hello {data.target}</h1> )}/>

请注意这里提到的警告: https://reactjs.org/docs/render-props.html#caveats

这包括使用PureComponents

相关问题