How can I make the data
prop bindable for editing?
#13401
Replies: 2 comments
-
I figured out why using an By using an Even still, this feels extremely janky, and so I'd love to know if there is a better approach. |
Beta Was this translation helpful? Give feedback.
-
There is a another pattern using const item = $derived.by(() => {
const state = $state({ current: data.item });
return state;
});
|
Beta Was this translation helpful? Give feedback.
-
I'm currently trying to make a site where the content can be edited, but there's no approach I have found that allows data to be updated as edits are made without breaking data reactivity between pages.
Essentially, my page has a value
data.item
which contains info about the current item. I wish to modify this value and have edits display across the UI as they are made, so that:What I've tried:
data.item
-- the value is not reactive, so edits don't get shown.let = thisItem $state(data.item);
-- the data updates across the site correctly, but it stops being reactive to page transitions.$effect
to updatethisItem
when the page changes -- either causes infinite loops, or doesn't work at all. Was nightmarish to debug.$state
specifically for when data is edited, then using an$effect
to copy back to the original when edits are made -- sincedata.item
is not reactive, it doesn't realise changes are made, and therefore doesn't re-render the affected parts of the app.For reference, here is the code I am working on
I'm completely stumped for what to do here. How can I approach this?
Beta Was this translation helpful? Give feedback.
All reactions