'Child component componentDidMount fires only once
I have an Home.js which renders 2 components, Header and Form Component. Form component has a button and dialog box. Clicking the button opens up the dialog.
Now as child ComponentDidMount is called before Parents, when Home is rendered, Form ComponentDidMount is fired.
Now when I click on the button in Form component, its ComponentDidMount is not getting fired.
Solution 1:[1]
componentDidMount is only called once in the lifecycle of any component, re-render will not reinitialize the component. componentDidUpdate will be called where you can manage your logic.
To make ComponentDIdMount re-render you need to change the props or state passed from home component.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Asad Ashraf |
