当我尝试在react中导入组件时,我遇到以下错误。
Uncaught TypeError: Cannot read property 'replaceChild' of null
at Function.replaceChildWithTree (index_bundle.js:4067)
at Object.dangerouslyReplaceNodeWithMarkup (index_bundle.js:21337)
at Object.dangerouslyReplaceNodeWithMarkup [as replaceNodeWithMarkup] (index_bundle.js:7162)
at ReactCompositeComponentWrapper._replaceNodeWithMarkup (index_bundle.js:22799)
at ReactCompositeComponentWrapper._updateRenderedComponent (index_bundle.js:22789)
at ReactCompositeComponentWrapper._performComponentUpdate (index_bundle.js:22739)
at ReactCompositeComponentWrapper.updateComponent (index_bundle.js:22660)
at ReactCompositeComponentWrapper.performUpdateIfNecessary (index_bundle.js:22576)
at Object.performUpdateIfNecessary (index_bundle.js:4277)
at runBatchedUpdates (index_bundle.js:1846)
我的组件是:
import React from 'react'
export default class NoticeCard extends React.Component {
render() {
return (
<section className="centered white">
<div className="container section">
<div className="center">
<p>Invalid Username/Password </p>
</div>
</div>
</section>
)
}
}
呈现组件,但控制台会抛出错误。
答案 0 :(得分:1)
此错误只是一种症状,代码中的某个地方正在被吞下。
这可能表明DOM已在React的控件之外进行了修改(父级为null,因此在替换子级时,它会尝试在null上调用replaceChild)。确保父组件未更改为null或未定义。
检查此主题:https://github.com/facebook/react/issues/6998
特别是这个评论: https://github.com/facebook/react/issues/6998#issuecomment-263336611