Update modal does not re-open with latest data
I have this snippet in my update modal
updating works, and the modal closes. however, when i re-open the modal, the initial data is the stale one and not the fresh
2 Replies
Hi @the_aceix. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Your issue is that when you re-open the modal, the form's initial values are not updated with the latest
This ensures that every time
- Watch the prop directly, not a copy. - Reset the form with the latest values when the prop changes and the modal is open. - Avoid destructuring or copying props for reactivity reasons. Let me know if you need a more specific code example! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
caseData
. This is a common reactivity pitfall in Vue/Nuxt when using the Composition API and destructuring props or initializing state from props.
Key points from the knowledge sources:
- Do not destructure props: If you destructure or copy prop values into local state, you lose reactivity. Instead, always use the prop directly or use toRefs(props)
to maintain reactivity. If you need to react to prop changes, set up a watcher on the prop itself, not on a copy or destructured value [Nuxt 3/Vue 3 Reactivity issue].
- Watching props: When using watch
, make sure you are watching the prop (or its ref) directly, not a value or a copy. For example, watch(() => props.caseData, ...)
will react to changes in caseData
[Toggle modal when changing text prop dynamically].
How to fix:
1. Watch the specific prop: Instead of watch([props], ...)
, watch () => props.caseData
directly.
2. Reset form with latest values: When caseData
changes and the modal is open, call resetForm
with the new values.
Example fix:
Why this works:This ensures that every time
caseData
changes (for example, when you re-open the modal with new data), the form is reset with the latest values. Avoid copying props into local state unless you have a specific reason and know how to sync them properly [Nuxt 3/Vue 3 Reactivity issue].
If you still see stale data, double-check that the parent is passing the latest caseData
to the modal when opening it.
---
Summary:- Watch the prop directly, not a copy. - Reset the form with the latest values when the prop changes and the modal is open. - Avoid destructuring or copying props for reactivity reasons. Let me know if you need a more specific code example! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@448141117368827905> Kapa.ai is still learning and improving, please let me know how I did by reacting below.