我正在使用 React.js 构建我的整个网站,如下所示:
React.render(
<div id="mainWrapper">
<MainHeader />
<div id="contentWrapper" className="contentWrapper">
<MainFlow data={example_data} />
<AddElementWrapper data={activities} />
</div>
</div>,
document.body
);
但是,在我的一个数据保存组件(即 MainFlow 或 AddElementWrapper)上调用 setProperties 时,我收到一个错误,指出我应该通过它们的父级操作数据。
Uncaught Error: Invariant Violation: replaceProps(...): You called `setProps` or `replaceProps` on a component with a parent. This is an anti-pattern since props will get reactively updated when rendered. Instead, change the owner's `render` method to pass the correct value as props to the component where it is created.
首先:我认为只有当我要操作的组件有另一个所有者时,这才会成为问题。但是,我的组件没有 React 组件作为owner,只有 HTML 元素作为parents。
我可以通过将所有应用程序数据附加到单个根组件来规避这个问题。但是,我想将某些数据集分开。有办法吗?