Retrieving the latest value

The current property being current is the unique thing about a ref. The property name current under the ref is given for a reason because, technically, there's nothing more current than a ref in React.

When we use a useState hook, we want to find out the current updated value of a state. Although we use the same word, current, the state can't be that current in some situations. We will use an example to demonstrate that.

Asynchronous state updates with useState

Let's say we have a button to increment a count, but instead of incrementing it right away, it waits for 3 seconds after the click:

Get hands-on with 1200+ tech skills courses.