Comments (7)
@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.
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 })
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.
@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.
https://gist.github.com/norricorp/011edb9f70280772f215797ee9203416
from svelte-paginate.
@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.
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.
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)
- Question no a bug HOT 1
- on:click HOT 1
- Update controls for accessibilty
- totalPages become undefined HOT 1
- Style LightPaginationNav HOT 1
- Active page number has a small bug HOT 1
- Warning during svelte kit build HOT 8
- Customizing the options of the LightPaginationNav navigation component
- Bug with using it in the newest version(s) of SvelteKit HOT 4
- Question HOT 1
- Project maintenance HOT 1
- Hint: Could not find a declaration file for module './DarkPaginationNav.svelte'. HOT 6
- pass state to slot
- Go to top after change currentPage HOT 1
- Is items a keyword
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte-paginate.