render is called before componentWillMount
See original GitHub issueIt seems like render is called before componentWillMount.
looking in the code it looks like things are happening in this order:
- render hook
- componentWillMount hook
- node is appended to the DOM
- componentDidMount hook
Its not as in react spec, but more importantly calling the hook before everything makes a lot of sense to me. otherwise there is no hook that allows touching the component before the first render.
I tried to play with the code a bit, but I couldn’t figure out how to move the hook to the right place.
mainly this line
rendered = hook(component, 'render', props, state, context);
is positioned before this
if (component.base) deepHook(inst, 'componentWillMount');
setComponentProps(inst, childProps, NO_RENDER, childContext);
renderComponent(inst, DOM_RENDER);
if (component.base) deepHook(inst, 'componentDidMount');
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:10 (7 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 >React Lifecycle Methods Render And ComponentDidMount
componentWillMount () method is the least used lifecycle method and called before any HTML element is rendered. If you want to see then...
Read more >Pre-Mounting with componentWillMount() · react-indepth
The first true life cycle method called is componentWillMount() . This method is only called one time, which is before the initial render....
Read more >React.Component
UNSAFE_componentWillMount() is invoked just before mounting occurs. It is called before render() , therefore calling setState() synchronously in this method ...
Read more >componentDidMount is called before render is completly done
componentWillMount is done. _renderSomething is called. I found out about this today when I ...
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 FreeTop 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
Top GitHub Comments
I think this being fixed probably warrants a party of some kind. Cheers, all! 🍻
Still doesn’t work in
5.0.0-beta.1
. Unfortunately,constructor
isn’t a real replacement. Many react components/mixins/decorators rely oncomponentWillMount
to be called beforerender
. It’s a lot of trouble to go through each and every one of them and rewrite them from using mixins to extending the component class instead, because there is no other way. You can’t overrideconstructor
on the prototype via decorator, or create a mixin that does it. I’ve stumbled upon this bug multiple times.componentWillMount
is essentially useless if it’s not called beforerender
.