此链接描述了如何在组件上设置ref并从父级调用其函数:https://facebook.github.io/react/tips/expose-component-functions.html
当我使用react-router并且我想要ref的组件是路由而父组件是根组件时,我如何实现这一点?
此链接描述了如何在组件上设置ref并从父级调用其函数:https://facebook.github.io/react/tips/expose-component-functions.html
当我使用react-router并且我想要ref的组件是路由而父组件是根组件时,我如何实现这一点?
1 回答
这样做:给
<RouteHandler/>
一个参考,像这样:<RouteHandler ref="routerHandler"/>
然后像这样打电话:
this.refs.routerHandler.refs.__routeHandler__.someFunctionOnActiveRoutesHandler()