Skip to content
Advertisement

They don’t load the elements inside the div that glider-js creates in nextjs

I am trying to create a carousel in nextjs with what I consume from an api and for that I am using glider-js. The problem is that the div that glinder-js creates does not contain the elements that I render when consuming an api.

This is the rendering code of the elements that I have

JavaScript

And the code of the glinder-js function is the following

JavaScript

this is what I get in the elements already rendered

Advertisement

Answer

Your load event is likely before Next rendered, try referencing the element instead.

You will also likely need to ensure you API has returned the required data prior to mounting.

Lastly, you will need to cleanup the glider instance on unmount. It has a lot of event listeners that will cause a memory leak if they are not removed on unmount.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement