this.refs componentDidMount 不再可用?

this.refs no longer available in componentDidMount?

来自 React v0.13 的变更日志:

"ref resolution order has changed slightly such that a ref to a component is available immediately after its componentDidMount method is called; this change should be observable only if your component calls a parent component's callback within your componentDidMount, which is an anti-pattern and should be avoided regardless"

那么,在 DOM 挂载后,是否有更好的方法访问 this.refs?我不喜欢使用 setTimeout(),但这是我看到在安装后处理特定 DOM 的最佳方法。我缺少替代方法吗?或者,将 onLoad 方法直接附加到组件的最佳方法是什么?

也许你读得太多了。

我的解释是 child 组件的所有引用都在 componentDidMount 中可用。

变化是它们在 child 组件自己的 componentDidMount 完成之前不可用(发生在 parent 组件之前)。如果您从 child 的 componentDidMount 内部调用一些回调,并且该代码尝试立即使用 ref,您只会受此影响。这看起来像一个 edge-case,正如他们所说,一个 anti-pattern.

因此 "normal usage" 不应受到此更改的影响。

请尝试并反馈。