timolins / react-hot-toast

Smoking Hot React Notifications 🔥
https://react-hot-toast.com
MIT License
9.44k stars 309 forks source link

refactor: Change from useEffect to useSyncExternalStore #359

Open minsgy opened 1 month ago

minsgy commented 1 month ago

as-is

The original code used useEffect to register the visibilitychange event on the document and update the state based on the document's visibility state in the event handler.

to-be

The updated code uses useSyncExternalStore to synchronize the external state changes. useSyncExternalStore provides a subscribe function to detect changes in the external state and a function to retrieve the current state. This allows for efficient observation of the document's visibility state changes and updating the state accordingly. These changes have improved the readability and efficiency of the code.

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-hot-toast ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2024 3:11pm
vercel[bot] commented 1 month ago

@minsgy is attempting to deploy a commit to the analytics-billing-vtest314 Team on Vercel.

A member of the Team first needs to authorize it.