Skip to main content
InterviewHubPRO
Section Overview
Q337

Question 337 of 407

Part 9: React Hooks Deep Dive (262 - 316)

83%
React Core & Hooks (407 Qs)•Part 9: React Hooks Deep Dive (262 - 316)

What will happen if you use setState() in constructor?

mid LevelHooks

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 state directly in the constructor.