slash icon indicating copy to clipboard operation
slash copied to clipboard

fix(@toss/react, @toss/use-loading): implement `useIsMountedRef` and modified `useLoading` to avoid state updates when the component is unmounted

Open okinawaa opened this issue 2 years ago • 1 comments

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
  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.

okinawaa avatar Jul 22 '23 13:07 okinawaa

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...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Jul 22 '23 13:07 netlify[bot]

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

vercel[bot] avatar Jun 03 '24 03:06 vercel[bot]