Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

How to make a fetch request everytime a prop changes in a component in Svelte?

$
0
0

Script part of a simple component, this component receives an id from its parent which triggers a fetch request based on that id. Problem here is that the component only mounts once and therefore, whenever a new prop is passed, there is no change. What is the best way to handle this situation?

  import request from "@src/modules/request"; //not important, performs a GET request  export let channelId;  let streams = [];  onMount(async()=>{    const response = await request({      url: `/streams?channel_id=${channelId}`,    });    streams = response.streams;  })

What I tried: using beforeUpdate but that resulted in multiple calls which was unncessary.


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>