You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
useOptimistic demo merges state via [...state, { text: newMessage, sending:true }], which may render a same message twice in the page at the same time(although it will render correct page immediately after the incorrect one)
merge message logic in this demo has to handle the situation:
state(array of the messages) already includes the sending message when the setMessages is called to make the page re-rendering.
The text was updated successfully, but these errors were encountered:
Hello @felismargarita the existing code effectively demonstrates the use of the UseOptimistic Hook with a simple example. Adding unnecessary complexity to handle duplicate messages detracts from the core purpose of the demo.
Additionally, your PR does not function as intended. The use of time as a unique identifier for messages is flawed, as identical messages can still appear multiple times if their timestamps differ, as evidenced in the screenshot.
image
Summary
useOptimistic demo merges state via [...state, { text: newMessage, sending:true }], which may render a same message twice in the page at the same time(although it will render correct page immediately after the incorrect one)
Page
https://react.dev/reference/react/useOptimistic
Details
merge message logic in this demo has to handle the situation:
state(array of the messages) already includes the sending message when the setMessages is called to make the page re-rendering.
The text was updated successfully, but these errors were encountered: