Facebook React: Uncaught Error: Invariant Violation: getDOMN

Facebook React: Uncaught Error: Invariant Violation: getDOMNode(): A component must be mounted to have a DOM node

本文关键字:Violation getDOMN Invariant Uncaught React Facebook Error      更新时间:2023-09-26

我有以下错误在reactjs内部:

Uncaught Error: Invariant Violation: getDOMNode():组件必须挂载才能拥有DOM节点

这是什么意思?我该怎么办呢?

堆栈跟踪:

invariantDev react.js:14392
ReactComponentBrowserEnvironment.Mixin.getDOMNode react.js:4072
React.createClass.scrollToBottom app.js:14124
(anonymous function)

这意味着在组件在DOM中呈现之前,您正在使用getDOMNode

你可以使用componentDidMount来等待运行代码,直到组件被挂载:

componentDidMount() {
    // do stuff here that requires the DOM to exist
}

你可以在这里阅读更多