andylib93
andylib93

Reputation: 163

How do I store a fetch response to a derived store in svelte?

I have a list of items which I consume from an own custom built API (in the example I'll use typicode) and want to display them. Additionally I want to add a client side search functionality. It is exactly like this REPL from this question.

But the given list is hardcoded, yet I can't seem to build a fetch call to get those items prior and afterwards display them. Only then can the user search and filter them.

Here is my REPL.

Upvotes: 3

Views: 1826

Answers (1)

CD..
CD..

Reputation: 74096

response.json() returns a promise, so you should await it.

Working example: https://svelte.dev/repl/a93ac2dcff584b2f8d11e430c6a96fa9?version=3.31.2

Upvotes: 4

Related Questions