componentDidMount is called before render is completly done
See original GitHub issueHi,
As much as I understand React component lifecycle, componentDidMount()
should fire after render()
is done, but I just found out today that this is not the case, and I’m not sure if this is a bug or lack of understanding from my side.
If I call a function that return some jsx
inside render()
, it always run after componentDidMount()
, so if I have this setup, componentDidMount()
always finish before _renderTable()
or _renderMessage()
export default class Table extends React.Component {
componentDidMount() {
...
}
render() {
const content = this.props.valid ? this._renderTable() : this._renderMessage()
return (
{content}
)
}
_renderTable() {...}
_renderMessage() {...}
}
Am I missing something? or is it some bug? Thanks!
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
React render() is being called before componentDidMount()
When a component is mounted it is being inserted into the DOM. This is when a constructor is called. componentWillMount is pretty much ......
Read more >How to understand a component's lifecycle methods in ReactJS
This method is called after the component gets mounted on the DOM. Like componentWillMount, it is called once in a lifecycle. Before the ......
Read more >Rendering and Updating Data using Component Lifecycle ...
The componentDidMount() method will be triggered as soon as the component is mounted or inserted into the DOM.
Read more >React Lifecycle - W3Schools
The componentDidMount() method is called after the component is rendered. This is where you run statements that requires that the component is already...
Read more >React.Component
shouldComponentUpdate() is invoked before rendering when new props or state are being received. Defaults to true . This method is not called for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you’re sure it’s a bug in React please provide an example reproducing it with React. If not, please ask for help on StackOverflow. We use the issue tracker for tracking bugs in React. Thanks!
:%s/componentWillMount/componentDidMount/g