Why Multiple Renders with useState in Non-Strict Mode?
When using useState in React, you might notice your component rendering more than once. This behavior, which can appear even without enabling strict mode, requires some clarification.
Upon clicking the "Change number" button, you'll observe two console statements ("here") due to an extra component render. The reason behind this is not strict mode, as previously suggested. Instead, React triggers a double render to facilitate a more deterministic development environment.
According to React's documentation, non-strict mode in development does the following:
This double rendering provides an opportunity to detect potential side effects in your code, highlighting performance issues or bugs early on. While this extra rendering doesn't occur in production, it serves as a valuable troubleshooting aid during development.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3