-
Why is linkURL not updated when you click handleSetUrlWithDestructure first time? https://codesandbox.io/p/sandbox/intelligent-tom-vgckjd
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It looks like this issue is related to React's rendering behavior. You're storing In contrast, in your This behavior is similar to how |
Beta Was this translation helpful? Give feedback.
It looks like this issue is related to React's rendering behavior. You're storing
linkURL
in thehandleSetUrlWithDestructure
function, where you destructure it from thestore
withconst { linkURL } = store;
at the top of your component. However, the component hasn't re-rendered to reflect any updates to that value.In contrast, in your
handleSetUrl
function, you're accessinglinkURL
directly from the store withstore.linkURL
. This ensures you're getting the updated value directly from the store, rather than from the component's current state.This behavior is similar to how
useState
anduseRef
work. WithuseState
, you need to wait for the component to re-render to get the updated value. B…