Urgent.News

650+ sources. One page. See who else covered it.

Editions

Tech

React useLatest Hook: Read Fresh State in Async Callbacks (2026)

Here's an autosave button that lies to the user: function Editor ({ docId }: { docId : string }) { const [ text , setText ] = useState ( "" ); const [ status , setStatus ] = useState < " idle " | " saving " | " saved " | " dirty " > ( " idle " ); async function save () { setStatus ( " saving " ); await api . save ( docId , text ); setStatus ( " saved " ); // ⚠️ but the user kept typing during the…

The React useLatest hook provides a way to read the latest state in asynchronous callbacks, avoiding stale closures that can cause issues with out-of-date data. In the example given, an autosave button in a text editor would sometimes fail to save the user's most recent input due to stale closures within the async save function.

The useLatest hook, from the @reactuses/core package, solves this problem by maintaining a reference to the latest value using a ref object. It does so by using a layout effect (useIsomorphicLayoutEffect) instead of a render effect, which guarantees that the ref's .current property is always updated with the most recent value. This approach allows the useLatest hook to be safely used in various asynchronous callbacks, such as setTimeout, setInterval, event listeners, and third-party SDK callbacks, ensuring that the latest data is always read, regardless of when the callback is executed.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

How to build and ship an iOS app without a Mac

If you want to put an app on the App Store, Apple requires you to build and sign it with Xcode, and Xcode only runs on macOS.

  • Purchase a Mac mini for $799 as a one-time hardware investment
  • Rent cloud Macs from services like MacStadium for $20/month to $100+/month
  • Use GitHub Actions for free macOS builds in public repositories

How I Cut MCP Token Usage by 91% (and Learned a Humbling Lesson About Tokenizers)

The Problem When you add MCP servers to your AI coding agent, each one dumps its full JSON schema into context. 255 tools across all servers = 39,964 tokens.

  • MCP servers consume large token space by adding full JSON schema to context
  • Mcptoon compresses JSON schema by 91%, reducing 39,964 tokens to 3,511
  • Mcptoon returns results in human-readable TOON format, saving even more tokens

Why your TestFlight build doesn't show up after a successful upload

You push, the build runs, the archive and export steps succeed, the upload step succeeds, the workflow finishes green. You open App Store Connect to check on it and TestFlight shows...

  • Build number must change with each upload, even if marketing version stays same
  • Use github.runnumber in GitHub Actions for dynamic build number
  • Verify dynamic build number substitution in archive step

More from Sunday 16 August →