facebook/react

Bug: useOptimistic hook showing stale values

CodingReaper1 opened this issue · 7 comments

React version: "^18" I tried on "^18.3.1" as well
image
image

The current behavior

Number and button appears for like 0.1 second and then dissapears
first i had this setup with database and little more complex ui then i reduced it to very simple arrays with number and button
Btw i did try this with useTransition as well neither that neither action works

The expected behavior

Number with button should appear without dissapearing

What do you expect to happen? You don't have a non-optimistic to actually track persistent state, nor do you have async work.

@vezaynk I expected component to show up and do not dissapear, I did have async work before I changed it to this simple array it was no different from what happening now, am I missing something? can you show me some code example or explain more what should be done?

@CodingReaper1 useOptimistic values are discarded after a transition has completed.optimisticNumbers will only show the optimistic result while the operation is running.

Once it has completed, non-optimistic state is expected to either catch up or be canceled.

@vezaynk I don't think thats how it works so you are telling me to revalidate data after async work is done?

Optimistic state is temporary is the short of it. If you want persistent state, use useState.

@vezaynk alright I though it would work like useState thanks for answers will close issue

closed