N
Nuxt7mo ago
Gobbo

reactive propagation through parameters

So, I believe I'm doing everything right but heres the layout I have a modal, in which I open by exposing an open function in the modal which sets up my state and refs.
const permissionIndex = ref(0)
const currentIndex = ref(-1)

let state = reactive<any>({})
...

function open(index: number, currentCondition: any, conditionIndex: number = -1) {
state = currentCondition
permissionIndex.value = index
currentIndex.value = conditionIndex

isOpen.value = true
}
const permissionIndex = ref(0)
const currentIndex = ref(-1)

let state = reactive<any>({})
...

function open(index: number, currentCondition: any, conditionIndex: number = -1) {
state = currentCondition
permissionIndex.value = index
currentIndex.value = conditionIndex

isOpen.value = true
}
and this is how I open it when creating new data and editing existing data @click="conditionModal?.open(index, {})" @click="conditionModal?.open(index, condition, kIndex)" My issue - when I want to edit this data, I only want it to edit the state and keep the state to itself, no propagation to anything else - so that when a user hits submit it'll emit and I can handle that outside of the modal however whats happening is, when I update a value in the modal - it updates the state but that also seems to update the "condition" variable I'm passing ( which is a nested object in a ref ) This isnt what I want, I want whatever I update in state to not propagate down the line and to be its own little thing without it updating anything outside.
1 Reply
Gobbo
GobboOP7mo ago
I assume its because I'm just setting the state value to currentCondition - so it has some form of linkage there Okay yeah, its because of that and a fix is state = { ...currentCondition } is that good practice or updating values inside of a reactive? I could use a re ftoo and just update the value
Want results from more Discord servers?
Add your server