What will happen if you use `setState()` in constructor?
When you use setState()
, then apart from assigning to the object state React also re-renders the component and all its children. You would get error like this: Can only update a mounted or mounting component. So we need to use this.state
to initialize variables inside constructor.
January 31, 2022
1912
Read more
What is React?
November 06, 2022
ReactJSHow to programmatically trigger click event in React?
November 06, 2022
ReactJS