Reputation: 149
I am facing a weird problem. I've written a React component which renders multiple custom child components via the array.map()-method like this:
public render(): React.ReactElement<IParentProps> {
return (
this.children.map((item, idx) => {
return (<Child customProperty={item}>);
}
);
}
All of my children get rendered, but componentDidMount gets called just once and not, like I would like it to be, every time a Child components gets created. It's crazy. I am using React 15.6.2 (can't upgrade, it's a, SharePoint 2019 solution).
Upvotes: 0
Views: 160
Reputation: 460
To further Murats answer, what you're likely looking for is componentDidUpdate()
Upvotes: 1
Reputation: 37604
You are misunderstanding the lifecycle hook. componentDidMount
means as the name suggests that the component is mounted (does not mean the render() function is done). It also does not get called for rendering elements at all.
Upvotes: 1