Giter Site home page Giter Site logo

Comments (7)

TahaSh avatar TahaSh commented on July 20, 2024

@norricorp the paginate function expects to get an object with these three keys: items, pageSize, and currentPage. In your case, you're not specifying items in the object. So, to fix it, update paginatedItems to this:

$: paginatedItems = paginate({ items: articles, pageSize, currentPage })

from svelte-paginate.

norricorp avatar norricorp commented on July 20, 2024

Hi @TahaSh, thanks for getting back so quickly
So I changed paginatedItems to

let items;
const [first, ...rest] = formattedArticles;
hero = first;
articles = rest;
}

onMount(fetchData);
$: paginatedItems = paginate({ items: articles, pageSize, currentPage })

In the browser console, I get
Uncaught TypeError: items is undefined
paginate paginate.js:2
update Home.svelte:39

line 39 in home.svelte is where paginatedItems is defined.

So then I changed "articles" to "items"

const [first, ...rest] = formattedArticles;
hero = first;
items = rest;

}

onMount(fetchData);
$: paginatedItems = paginate({ items, pageSize, currentPage })

</script>
{#if hero} {/if} {#if items}
{#each paginatedItems as article, index} {/each}
{/if}

And, once again, in console

Uncaught (in promise) TypeError: items is undefined
paginate paginate.js:2
update Home.svelte:39

Any other ideas? Obviously I am doing something very wrong.

from svelte-paginate.

TahaSh avatar TahaSh commented on July 20, 2024

@norricorp it's actually hard for me to tell without seeing the full code. But I think it's related to the code fetching the data. Also, please make sure you're using the latest version v0.1.0.

Feel free to send me a gist (or whatever you like) of the homepage full code and I'll take a look.

from svelte-paginate.

norricorp avatar norricorp commented on July 20, 2024

https://gist.github.com/norricorp/011edb9f70280772f215797ee9203416

from svelte-paginate.

TahaSh avatar TahaSh commented on July 20, 2024

@norricorp it's erroring because articles is undefined initially, but paginate is expecting an array. So you can fix it by checking if articles is valid before calling paginate:

$: paginatedItems = articles && paginate({ items: articles, pageSize, currentPage })

Also, don't forget to add this check for <PaginationNav />:

{#if articles}
  <PaginationNav
    totalItems="{articles.length}"
    pageSize="{pageSize}"
    currentPage="{currentPage}"
    limit="{1}"
    showStepOptions="{true}"
    on:setPage="{(e) => currentPage = e.detail.page}"
  /> 
{/if}

Please let me know if you have any other questions :).

from svelte-paginate.

norricorp avatar norricorp commented on July 20, 2024

Hi @TahaSh ,
that worked. Thank you so much for great support.
Are you intending to get this to version 1.0? What extra functionality do you plan? (I realise nothing to do with my issue - just interested)

from svelte-paginate.

TahaSh avatar TahaSh commented on July 20, 2024

Hi @norricorp, I'm really glad that it worked.

I have no plans for this package at the moment, but if you have anything in your mind for this package or even a new package, I would be more than happy to put it on my list. Thanks!

from svelte-paginate.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.