• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Svelte: Get User Input Callback via Store Function

Resolved: Svelte: Get User Input Callback via Store Function

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

What I’m trying to do here may not be possible, but as a newcomer to Svelte, I hope it is. ๐Ÿ˜„
I have a delete button in a component that opens a globally available modal that serves as a confirmation dialog. The modal component is in my __layout.svelte so I can invoke it from anywhere in my app.
Here is my modal store:
Last of all, here is my component in my app where I actually initiate the delete process by clicking a link that shows the delete confirmation modal:
I’m unclear on how to connect a callback function through my confirmTrash function to pass the user’s response in the modal back to where the modal was invoked. Is this possible?

Answer:

For this to work, you just have to pass in function and call it accordingly.
Then call it in the component:
REPL example
I would not use singleton component like this but create new instances using the client-side component API. It is less redundant, leads to a cleaner life cycle and less unnecessary global state.
Example of that:
Usage:
REPL example

If you have better answer, please add a comment about this, thank you!

callback javascript svelte svelte-store typescript
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Use Svelte Component as Slot

26/03/2023

Resolved: Vaadin 14.9 – Redirect on Session Destroy Event

26/03/2023

Resolved: How to separate multiple answers in one column, for multiple columns, by creating extra columns

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.