Optimistic UI Implementation Issue: Retrieving Correct Derived Value in Remix App #6942
Unanswered
AlexGodard
asked this question in
Q&A
Replies: 1 comment
-
I don't know if you've found a solution to your issue already, but I had exactly the same issue. To fix the issue I've specified the type for useFetcher to use the action rather than the loader:
This then gives the following console output, and fixes the flashing, (it's editing a text input from 'Name' to 'Name - New') |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to implement optimistic UI in my app.
Let's say I have this form UI:

Which submits every time you click an option. Here's the code sandbox.
If I click on the "banana" option, the UI will go through those 4 states:

Notice how the 3rd state (the action has finished, so
fetcher.formData
is gone) showsapple
as the optimistic value -- Is there anything I can do to getorange
as the derived "optimistic value" instead?I've added 1 second delays to my loader and action, and it only stays on the 3rd state for a fraction of a second. It's so quick you can't see it, but if you slow down the network and CPU you can see the radio button flash + a red square box (only shown during the 3rd state).
I'd like to do this without a
useEffect
if possible, but I realize I might not have a choice.Here's the full code:
Would appreciate any help!
Beta Was this translation helpful? Give feedback.
All reactions