SvelteKit: ‘filtered’ is not a store with a ‘subscribe’ method


I am trying to write a Pokedex SvelteKit app (as a tutorial from James Q Quick). When I save my index.svelte file – it says the error in the title of this question.

My index.svelte code is as follows:

<script>
    import Nav from '../components/nav.svelte'
    import {pokemon} from '../stores/pokestore'
    import PokemanCard from "../components/pokemanCard.svelte"

    let searchTerm = "";
    let filtered = [];

    $: { // Reacts to any data that changes ($: {what will happen when data changes})
        if (searchTerm !== pokemon.searchTerm) {
            searchTerm = pokemon.searchTerm;
            filtered = filtered(pokemon.pokemons, searchTerm);
        }
    }
</script>

<svelte:head>
    <title>Svelte Kit Pokedex</title>
</svelte:head>

<!-- All HTML Work -->
<h1 class="text-4xl text-center m-8 uppercase">SvelteKit Pokedex</h1>
<input type="text" class="w-full rounded-md text-lg p-4 border-2 border-gray-200" placeholder="Search Pokemon" bind:value={searchTerm}>


<style>
</style>


<div class="py-4 grid gap-4 md:grid-cols-2 grid-cols-1">
    {#each $filtered as pokeman}
    <PokemanCard pokeman={pokeman} />
    {/each}
</div>

How do I fix this?

Thanks 🙂



Source link

Latest articles

Related articles

Leave a reply

Please enter your comment!
Please enter your name here