S
SolidJS3mo ago
Mr Void

disable untrack when param changes

is it possible to, again, track an untracked signal when useParams parameters changes. I have a component that retrieves some data from the store based on a URL parameter.
const params = useParams()
const [currentNote, setCurrentNote] = createSignal<Note>()

createEffect(async () => {
// <data from store depending on params.note_id>
setCurrentNote(...)
})

<Editor
// untracking to avoid bug in editor whenever data is autosaved
// however, this needs to be updated when URL param changes
data={untrack(() => currentNote()?.data) || undefined}
/>
const params = useParams()
const [currentNote, setCurrentNote] = createSignal<Note>()

createEffect(async () => {
// <data from store depending on params.note_id>
setCurrentNote(...)
})

<Editor
// untracking to avoid bug in editor whenever data is autosaved
// however, this needs to be updated when URL param changes
data={untrack(() => currentNote()?.data) || undefined}
/>
2 Replies
Raqueebuddin Aziz
I think what you need is ephemeral state, check this out: https://primitives.solidjs.community/package/memo/#createwritablememo Basically in your editor create a writabl memo like createWritableMemo(() => props.data) and remove the untrack from
<Editor
// untracking to avoid bug in editor whenever data is autosaved
// however, this needs to be updated when URL param changes
data={currentNote()?.data}
/>
<Editor
// untracking to avoid bug in editor whenever data is autosaved
// however, this needs to be updated when URL param changes
data={currentNote()?.data}
/>
then update the writable memo in your editor untill the thing is saved, once the thing is saved update your params secondly, using createEffect to set a signal is not best practice, you should create a derived signal if possible
Alex Lohr
Alex Lohr3mo ago
You are manually rebuilding a reduced version of createResource to handle your async state.
Want results from more Discord servers?
Add your server