feat(hooks): add 'useIsMounted'#244
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #244 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 33 34 +1
Lines 836 847 +11
Branches 254 258 +4
=========================================
+ Hits 836 847 +11 🚀 New features to boost your workflow:
|
|
According to our design principles, we might need to carefully consider whether providing this hook is the right approach. |
|
Thank you for raising that point — I completely agree with the importance of respecting React’s lifecycle and avoiding interference. That said, I believe In fact, this pattern complements React’s lifecycle by acknowledging the asynchronous nature of effects, especially in environments where race conditions or delayed executions (e.g., While it’s true that React encourages effects to be scoped correctly, in practice developers still face scenarios where external timing or delayed callbacks can lead to unintended updates. So rather than introducing lifecycle interference, this hook serves as a passive safety utility — one that aligns with React’s declarative philosophy by helping avoid imperative leaks. |
|
@sukvvon Thank you for the clean implementation — the code quality is excellent (SSR-safe, usePreservedCallback, 100% coverage). Before merging, we'd like to discuss one architectural concern: React 18 removed the "setState on unmounted component" warning (reactwg/react-18#82). The React team's position is that That said, We'd like to align with @zztnrudzz13 on whether this fits our library scope before proceeding. Will follow up soon! |
|
Following up here — after discussing internally, we’ve decided to close this PR. While the implementation is solid, useIsMounted is based on a pattern that the React team generally discourages. isMounted checks don’t actually prevent memory leaks; they mainly hide the symptom (skipping a state update) rather than addressing the root cause. In most cases, the recommended approach is to cancel async work or clean up subscriptions properly in useEffect. Because of this, adding a hook like this would likely result in something we’d eventually mark as deprecated. For that reason, we don’t think it fits well within the long-term direction of this library. Thanks again for the clean implementation and for taking the time to contribute 🙏 |
Overview
Checklist
yarn run fixto format and lint the code and docs?yarn run test:coverageto make sure there is no uncovered line?