reboottime / React-Develpment

Some notes, thought, articles or source code readings aggregated here about React Web development.
0 stars 0 forks source link

Refreshed React 18 concepts #108

Open reboottime opened 3 hours ago

reboottime commented 3 hours ago

Overview

This article systematically track through React 18.

reboottime commented 3 hours ago

useTransition

https://www.youtube.com/watch?v=1xjSQJWejZM&ab_channel=CosdenSolutions.

Understand it using plain term

Let me explain useTransition in React 18+ in a business-friendly way.

Imagine you're running a busy restaurant. When customers place orders, you have two options:

  1. Traditional way (without useTransition): Your waitstaff stops everything they're doing to process each order immediately. While this sounds efficient, it can make the restaurant feel "frozen" or unresponsive during busy times, frustrating other customers.

  2. Using useTransition: This is like having your waitstaff say "I'll get right on that" to the customer (keeping the interface responsive), while processing the order in the background. The restaurant keeps running smoothly, and customers can continue interacting with menus or asking questions.

In technical terms, useTransition allows your app to:

Business Benefits:

Understanding it from code level

// Without useTransition
setActiveTab(tab);  // This blocks rendering until complete

// With useTransition
startTransition(() => {
    setActiveTab(tab);  // This can be interrupted by other updates
                        // and keeps old UI visible while processing
});