In the React documentation they say:
React also supports using a string (instead of a callback) as a ref prop on any component, although this
Originally posted by danabramov on https://news.ycombinator.com/edit?id=12093234
- String refs are not composable. A wrapping component can’t “snoop” on a ref to a child if it already has an existing string ref. On the other hand, callback refs don’t have a single owner, so you can always compose them.
- String refs don’t work with static analysis like Flow. Flow can’t guess the magic that framework does to make the string ref “appear” on
this.refs, as well as its type (which could be different). Callback refs are friendlier to static analysis.- The owner for a string ref is determined by the currently executing component. This means that with a common “render callback” pattern (e.g.
), the wrong component will own the ref (it will end up onDataTableinstead of your component definingrenderRow).- String refs force React to keep track of currently executing component. This is problematic because it makes
reactmodule stateful, and thus causes weird errors whenreactmodule is duplicated in the bundle.