0 votes
in ReactJS by
What will happen if you use setState() in constructor?

1 Answer

0 votes
by

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.

...