我正在使用react-router进行导航。我有一些组件,需要登录才能看到它们。
因此,我得到了以下内容:(来自react-router中的以下文档)
<Route
{...rest}
render={props =>
isLoggedIn()
? <Component {...props} />
: <Redirect
to={{
pathname: '/login',
state: {from: props.location},
}}
/>}
/>然而,这有一个问题,因为jsx-no-bind不允许箭头函数。解决这个问题的正确方法是什么?或者应该忽略这一点,因为出于某种原因,它没有遭受相同的性能影响?
发布于 2018-06-13 19:34:07
关于渲染道具的官方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的使用
https://stackoverflow.com/questions/45042687
复制相似问题