I'm newer to react and I'm stumped by this issue. I'm using a primereact carousel and trying to do 2 things.
- In the item template I want to show 'Showing X of X orders'.... essentially showing where they are at in the array of orders.
- I want to reload the data each time the page is changed.
What I am running into is whenever I use this code below the carousel loses it's functionality. The left arrow is never enabled and the markers below the carousel is always set at one. So it's like it can no longer keep track of where it's at.
<div className="carousel-wrapper">
<Carousel
onPageChange={test}
value={filteredOrders}
numVisible={1}
numScroll={1}
responsiveOptions={[
{
breakpoint: "1024px",
numVisible: 1,
numScroll: 1,
},
{
breakpoint: "768px",
numVisible: 1,
numScroll: 1,
},
{
breakpoint: "560px",
numVisible: 1,
numScroll: 1,
},
]}
itemTemplate={itemTemplate}
/>
</div>
function test() {
console.log("test");
}
Even with this simple code here I can see in the console "test" every time I click the right arrow. But again the carousel loses functionality. If I remove the onPageChange line form the carousel it goes back to working.
It is because when you added
onPageChangeyou are telling the component you want to control paging. This is referred to as "uncontrolled mode" vs "controlled mode" where the component is handling the paging.See this fully working example: https://stackblitz.com/edit/otq6af?file=src%2FApp.tsx