since componentWillMount is depreciated in new versions of React Native is componentWillMount and componentDidMount plays the same role? In my research componentWillMount is executed before 1st render and componentDidMount is executed after 1st render, Now the questions is that is there any component that is executed automatically before the 1st render in react native?
Asked
Active
Viewed 368 times
-3
-
Does this answer your question? [What is the difference between componentWillMount and componentDidMount in ReactJS?](https://stackoverflow.com/questions/29899116/what-is-the-difference-between-componentwillmount-and-componentdidmount-in-react) – Jared Smith Oct 09 '20 at 11:10
-
I don't think that is the same question, the answer provided there is already incorporeted in Usama question – gbalduzzi Oct 09 '20 at 11:12
1 Answers
0
You can use the constructor()
to do stuff before the first render
UNSAFE_componentWillMount() is invoked just before mounting occurs. It is called before render(), therefore calling setState() synchronously in this method will not trigger an extra rendering. Generally, we recommend using the constructor() instead for initializing state.

gbalduzzi
- 9,356
- 28
- 58