I'm building my whole site with React.js like this:
React.render(
<div id="mainWrapper">
<MainHeader />
<div id="contentWrapper" className="contentWrapper">
<MainFlow data={example_data} />
<AddElementWrapper data={activities} />
</div>
</div>,
document.body
);
However, calling setProperties on one of my data-holding components, namely MainFlow or AddElementWrapper, I get an error, stating that I should manipulate the data via their parents.
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.
First off: I thought that this would only be a problem if there is another owner for the component I want to manipulate. However, my components don't have React components as owners, just HTML elements as parents.
I could circumvent this problem by attaching ALL application data to a single root component. However, I'd like to keep certain sets of data separate. Is there a way?
You should define a Wrapper component and maintain the state of data there and simply invoke setState when data changes from the outside world.