fix(@toss/react, @toss/use-loading): implement `useIsMountedRef` and modified `useLoading` to avoid state updates when the component is unmounted
Overview
Merge @tossteam/use-loading
@toss/react
Implemented useIsMountedRef
Motivation(reference)
- Avoid memory leaks setting states when component are unmounted;
- Control when component already mounted;
- Common error when setting state to unmounted component:
@toss/use-loading
Preventing State Updates After Unmounting in useLoading Hook
I have made changes to the useLoading hook to address the issue where the state gets updated after the component calling useLoading is unmounted. This problem typically occurs when useLoading receives a promise that might lead to the unmounting of the component. When the promise resolves after the component is already unmounted, it triggers a "Can't perform a React state update on an unmounted component" warning.
The revised version of the useLoading hook ensures a more reliable and stable behavior when dealing with asynchronous tasks and component unmounting.
PR Checklist
- [x] I read and included theses actions below
- I have read the Contributing Guide
- I have written documents and tests, if needed.
Deploy Preview for slash-libraries ready!
| Name | Link |
|---|---|
| Latest commit | 2c55d76a627c9774d2b7cf97dba281d505c1ee83 |
| Latest deploy log | https://app.netlify.com/sites/slash-libraries/deploys/64bd486c5876b400089a50e9 |
| Deploy Preview | https://deploy-preview-296--slash-libraries.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| slash | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 3, 2024 3:13am |