In my React component, I have a method populateData()
This method is called at various places in my Component.
It is called from render, componentDidUpdate, componentDidMount
etc.
Now, there is a special condition in the method populateData()
which only needs to be executed when it is called from componentDidMount
.
Is it possible to know which lifecycle method is the caller, without passing that as an argument to the method?
Example code for populateData()
:
const populateData = () => {
//do something
if(caller === 'componentDidMount') {
//do this also
}
}