1

This link describes how you can set a ref on a component and call its functions from a parent: https://facebook.github.io/react/tips/expose-component-functions.html

How do i achieve this when i'm using react-router and the component I want to ref is a route and the parent is the root component?

user2827377
  • 1,381
  • 2
  • 16
  • 26

1 Answers1

1

This works: Give <RouteHandler/> a ref, like this: <RouteHandler ref="routerHandler"/>

Then call like this: this.refs.routerHandler.refs.__routeHandler__.someFunctionOnActiveRoutesHandler()

user2827377
  • 1,381
  • 2
  • 16
  • 26
  • Any idea what the react-router 2.x equivalent of this is? – Scott Stafford Jan 22 '16 at 19:38
  • 1
    React Router 2.0 gives you this.props.children. Use this approach to get a ref: http://stackoverflow.com/questions/29568721/getting-dom-node-from-react-child-element, and this approach to call a function: https://facebook.github.io/react/tips/expose-component-functions.html. Keep in mind this is an anti-pattern. – user2827377 Jan 23 '16 at 14:57