I'm new to React.
In root.render I instantiate my ProjectGrid (class-based component) with code something like the following:
root.render(
<StrictMode>
<App />
<ProjectGrid project={p} />
</StrictMode>
);
Basically, the ProjectGrid
component displays the Project
object -- simple user-defined type.
Later, in a Button onClick
, I'd like to generate a new Project
and update the state of the ProjectGrid
so it will now display the new Project
object.
How do I get a reference to the JSX-created React component?
Thought This Would Work: But Returns DOM Element
I thought it would be something like the following:
let px = document.querySelector('#ProjectGrid');
let pg = ReactDOM.findDOMNode(px);
if (pg !== undefined && pg !== null) {
pg.setState({ project: p });
}
However, this doesn't work because the px
object is actually a DOM element not a React Component.