On stores - init and set await to get some more data
This initializes the store with an empty array and then, once the question data is fetched, asynchronously sets the data as the store’s value
import { readable } from "svelte/store"
export const questionStore = readable([], set => getQuestionData(set))
const getQuestionData = (set) => {
const url =
"https://opentdb.com/api.php?amount=10&category=27&difficulty=easy&type=multiple"
fetch(url)
.then(res => res.json())
.then(data => set(data.results))
}
https://svelte.dev/repl/fc127fb581f1484e91c20ec006432ce9?version=3.46.4
pnpm init --yes @svelte-add/[email protected] my-new-svelte-app -- --with tailwindcss+typescript+mdsvex