feat(core/hooks): add 'useIsClient' hook#219
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #219 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 33 34 +1
Lines 836 842 +6
Branches 254 256 +2
=========================================
+ Hits 836 842 +6 🚀 New features to boost your workflow:
|
|
We have similar discuss here: #202 |
|
|
|
I understand that distinguishing between the server and client environments is important, |
|
Using This allows:
In React, a hook like |
|
@sukvvon I think using useSyncExternalStore would be a better approach since it avoids unnecessary re-renders compared to useEffect. Also, i think it follows React's recommended approach in a more standardized way, instead of relying on typeof window checks. What do you think? |
|
If our library targets |
|
@sukvvon Thank you for your patience — this PR has been open for a while and we really appreciate both the implementation and the thoughtful discussion (especially the useSyncExternalStore trade-off). We've reviewed the code and confirmed No overlap with
Implementation approach is correct — To merge, we need:
Looking forward to getting this merged! |
|
@zztnrudzz13 FYI — once this lands, we're planning to:
This aligns with our architecture rule (mobile depends on core, not the other way around). Will handle as a follow-up PR. |
3869fb5 to
7c91c29
Compare
|
@kimyouknow Thank you for the detailed review! All three items have been addressed in 90781a2 and d81ab5c:
Please let me know if anything else needs adjustment! |
kimyouknow
left a comment
There was a problem hiding this comment.
LGTM! thanks for contributing
Overview
Add
useIsClienthook that returnstrueonly after client-side hydration, preventing SSR/CSR hydration mismatches.packages/core/src/hooks/useIsClient/)Checklist
yarn run fixto format and lint the code and docs?yarn run test:coverageto make sure there is no uncovered line?