🔧 ProgrammierungGitHub Release: dependabot/dependabot-core v0.395.0 (07.09.2026)(07.09.2026 um 15:21 Uhr)
🔧 ProgrammierungGitHub Release: dependabot/dependabot-core v0.396.0 (14.09.2026)(14.09.2026 um 19:05 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vpython/v1.4.0 (02.09.2026)(02.09.2026 um 04:47 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vjavascript/v1.5.0 (02.09.2026)(02.09.2026 um 04:47 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vjavascript/v1.6.0 (06.09.2026)(06.09.2026 um 17:45 Uhr)
🔧 Programmierungclawpatrol v0.5.10(13.09.2026 um 02:54 Uhr)
⚠️ Malware / Trojaner / VirenCAPE-parsers v0.1.69(13.09.2026 um 04:14 Uhr)
⚠️ Malware / Trojaner / Virendarknet-mcp-server(13.09.2026 um 04:55 Uhr)
🐧 Linux Tippsazurelinux v3.0.20260909-3.0(13.09.2026 um 09:51 Uhr)
🕵️ Sicherheitslückenatomicvulns(13.09.2026 um 10:36 Uhr)
🔧 ProgrammierungGitHub Release: dependabot/dependabot-core v0.395.0 (07.09.2026)(07.09.2026 um 15:21 Uhr)
🔧 ProgrammierungGitHub Release: dependabot/dependabot-core v0.396.0 (14.09.2026)(14.09.2026 um 19:05 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vpython/v1.4.0 (02.09.2026)(02.09.2026 um 04:47 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vjavascript/v1.5.0 (02.09.2026)(02.09.2026 um 04:47 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vjavascript/v1.6.0 (06.09.2026)(06.09.2026 um 17:45 Uhr)
🔧 Programmierungclawpatrol v0.5.10(13.09.2026 um 02:54 Uhr)
⚠️ Malware / Trojaner / VirenCAPE-parsers v0.1.69(13.09.2026 um 04:14 Uhr)
⚠️ Malware / Trojaner / Virendarknet-mcp-server(13.09.2026 um 04:55 Uhr)
🐧 Linux Tippsazurelinux v3.0.20260909-3.0(13.09.2026 um 09:51 Uhr)
🕵️ Sicherheitslückenatomicvulns(13.09.2026 um 10:36 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 2 Min Lesezeit
0

React 19 : useOptimistic Hook

↗ Quelle (dev.to)
🗣️ Stimme:

React 19 introduced several new features, including the useOptimistic hook.



useOptimistic help us in updating the UI when our async function is in progress.






Lets understand the use case of useOptimistic with an example




  1. When a user likes a post on Instagram.

  2. Client(Instagram app on user device) will make an API call to server for updating the number of likes. (asynchronous action)

  3. Once client receives the response from the server, UI will be updated accordingly with correct number of likes.



If the server is slow, there may be a delay in receiving the response and updating the UI, leading to a poor user experience.






The best way to enhance user experience




  1. User likes a post on Instagram.

  2. UI will display updated likes count without any delay.

  3. Client will make an API call to server. (asynchronous action)

  4. If API call is success, there will be no change in the UI (because we are already displaying updated likes count).

  5. If the API call is failed, like will be removed.



useOptimistic hook assists in managing likes while our asynchronous code (such as an API call in this case) is still underway.



API call Success





API call Failed








Code






CODE
import { HeartFilledIcon, HeartIcon } from "@radix-ui/react-icons";
import { Box, Strong, Text } from "@radix-ui/themes";
import { useOptimistic, useState, useTransition } from "react";

const UseOptimisticExample = () => {
const [likes, setLikes] = useState(100);
const [isPostLiked, setIsPostLiked] = useState(false);
const [optimisticData, setOptimisticData] = useOptimistic(
{ likes, isPostLiked },
(currentState, newLikes) => {
return { likes: currentState.likes + newLikes, isPostLiked: true };
}
);
const [, startTransition] = useTransition();

const onLikeClick = () => {
startTransition(async () => {
setOptimisticData(1);
// Simulating API call
await new Promise((resolve, reject) => {
console.log("Request sent to server");
setTimeout(() => {
resolve(likes + 1); // To simulate API call success
// reject("API call failed"); // To simulate API call failure
}, 8000);
})
.then((newLikes) => {
console.log("API call success");
setLikes(newLikes);
setIsPostLiked(true);
})
.catch((error) => {
console.error(error);
});
});
};

return (
<Box py="1" px="2">
{optimisticData.isPostLiked ? (
<HeartFilledIcon
color="red"
style={{ height: "50px", width: "50px", cursor: "pointer" }}
onClick={onLikeClick}
/>
) : (
<HeartIcon
style={{ height: "50px", width: "50px", cursor: "pointer" }}
onClick={onLikeClick}
/>
)}
<br></br>
<Text>
<Strong>{optimisticData.likes} Likes</Strong>
</Text>
</Box>
);
};

export default UseOptimisticExample;



Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
10 Quellen
GitHub Release: dependabot/dependabot-core v0.393.0 (24.08.2026)
1 Quelle
clawpatrol v0.5.10
1 Quelle
CAPE-parsers v0.1.69
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten React 19 : useOptimistic Hook

Thematisch verwandte Begriffe: React, useOptimistic, Hook · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...