Sergei
Sergei
SSolidJS
Created by Sergei on 9/28/2023 in #support
How to trigger update on resource update?
Thank you. I followed your advice.
10 replies
SSolidJS
Created by Sergei on 9/28/2023 in #support
How to trigger update on resource update?
I think I figured it out. I basically had to follow https://www.solidjs.com/tutorial/stores_createstore?solved Thank you. That little comment pointed me into the right direction.
10 replies
SSolidJS
Created by Sergei on 9/28/2023 in #support
How to trigger update on resource update?
ok, I switched to store, but I still don't get update: const [list, setList] = createStore<EmailListItem[]>([]) const [listResource] = createResource(async () => await ... this loads array of objects) createEffect(async () => { if (!listResource.loading) { setList(listResource) } }) // click event handler const onAddToList: JSX.EventHandlerUnion<HTMLFormElement, Event & { submitter: HTMLElement}>|undefined = async (ev) => { ev.preventDefault() try { await item.post() listResource().push(item) // setList(listResource) } catch (err) { setErr(err) } } And then rendering code: <For each={list}>{(listItem, idx) => <p class="item">{listItem.name}</p> }
10 replies
SSolidJS
Created by Sergei on 9/28/2023 in #support
How to trigger update on resource update?
It appears I may have to study how https://www.solidjs.com/tutorial/stores_mutation works.
10 replies
SSolidJS
Created by Sergei on 9/28/2023 in #support
How to trigger update on resource update?
But then the above seems to be incorrect. I can only have const [list] = createResource(async () => await (...)) thus, there is no setList() function.
10 replies
SSolidJS
Created by Sergei on 9/28/2023 in #support
How to trigger update on resource update?
Basically I load list of items from REST API: const [list, setList] = createResource(async () => await (creates an array of objects here)) then I have a button to add new item. The handler makes POST of the item and then tried to add it to the list: try { await item.post() list().push(item) } catch (err) { setErr(err) } And adding item to the list did not trigger update. Perhaps I need to call setList()
10 replies