question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

componentDidMount is called before render is completly done

See original GitHub issue

Hi,

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:closed
  • Created 8 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
gaearoncommented, Aug 11, 2016

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!

4reactions
jimfbcommented, Jan 12, 2016

:%s/componentWillMount/componentDidMount/g

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found