I have child component, inside the render function I am populating a view like this
{this.state.supportTopicMetadataTreeNode.children.map(
(metadata: SupportTopicMetadataTreeNode) => (
<div>
<SupportTopicMetadataContainer
supportTopicMetadataTreeNode={metadata}
></SupportTopicMetadataContainer>
</div>
)
)}
Which is type of SupportTopicMetadataTreeNode Like below:
export default class SupportTopicMetadataTreeNode {
public data: SupportTopicMetadata;
public children: SupportTopicMetadataTreeNode[];
}
In Parent Component I am calling above Component like below:
{this.state.metadataList && this.state.metadataList.map((metadata: SupportTopicMetadataTreeNode) =>
<div>
<SupportTopicMetadataContainer supportTopicMetadataTreeNode={metadata}>
</SupportTopicMetadataContainer>
</div>
)}
Before calling Child function above I am setting state with my current modified value to metadaList like this:
this.setState({ metadataList: filteredList });
But in child component it doesn't populate with valid data that is filteredList. I have checked that state is correctly assigned my expected value to metadataList Not getting what the problem is?
I am also trying to pass filteredList to child component so that can loop directly on this.state.supportTopicMetadataTreeNode.children
Any idea how to pass that to child state or variable that defined on child state?
Update:
I have initialize the constructor like below:
constructor(props: ISupportTopicMetadataEntryContainerProps) {
super(props);
this.state = {
supportTopicMetadataTreeNode: props.supportTopicMetadataTreeNode,
};
}
So I need not to call like this this.props.supportTopicMetadataTreeNode.children as answered like this. Now I can get that this.state.supportTopicMetadataTreeNode.children. Don't understand what's the problem.