Unique bullets for page navigation in Swiper.js/react

I've been attempting to implement custom paginations for my component in order to have bullets outside the container, but unfortunately they are not showing up in the DOM.

Below is the code snippet of the component:

export function CommentSlider({ comments }: CommentSliderProps): ReactElement {
  return (
    <div className="px-4 relative">
      <Swiper
        modules={[Pagination]}
        pagination={{
          clickable: true,
          el: '.swiper-custom-pagination',
        }}
        slidesPerView={1}
        className="mt-4 h-auto !mx-0"
      >
        {comments.map(
          (comment) =>
            comment !== "empty" && (
              <SwiperSlide key={uuid()} className="!px-2">
                <div className="h-full w-0.5 bg-dark-gray absolute top-0 left-0" />
                <Comment comment={comment} />
              </SwiperSlide>
            ),
        )}
      </Swiper>
      <div className="swiper-custom-pagination" />
    </div>
  );
}

Here's a visual representation from the browser:

click here to view image description

I also tried implementing the additional options mentioned above, but the outcome remained unchanged.

      <Swiper
        modules={[Pagination]}
        pagination={{
          clickable: true,
           type: "bullets",
           el: ".comment-pagination",
           bulletClass: ".comment-pagination__item",
           renderBullet: (index, className) => {
             return `<span class="${className}" />`;
           },
          el: '.swiper-custom-pagination',
        }}
        slidesPerView={1}
        className="mt-4 h-auto !mx-0"
      >

Answer №1

Ensure you have included the required Pagination JavaScript module and CSS at the beginning of your code for it to function correctly.

import "swiper/css/pagination";
import { Pagination } from "swiper/modules";

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implement a function to delete an item from an array within a React object by utilizing the UseState hook

I am facing a challenge in React as I attempt to remove an element from an array within an array of objects using the UseState hook. Despite my efforts, the interface does not re-render and the object remains in place. From what I understand, in order for ...

I continue to encounter the same error while attempting to deliver data to this form

Encountering an error that says: TypeError: Cannot read properties of null (reading 'persist') useEffect(() => { if (edit) { console.log(item) setValues(item!); } document.body.style.overflow = showModal ? "hidden ...

What is preventing useEffect from accessing my state variable within a return statement?

I'm struggling to figure out why my useEffect() React function is unable to access my Component's state variable. My goal is to create a log when a user abandons creating a listing in our application and navigates to another page. I've imple ...

What is preventing MenuItemLink from being displayed in the menu?

I have created a unique page for users to purchase subscriptions, but I am having trouble accessing that page because the button is not appearing in the menu. I followed the steps outlined in the official guide, but only the dashboard and resources buttons ...

Issues concerning the application of Nextjs and tailwind styling have arisen

My goal is to achieve a scroll effect where my navbar changes color as the user scrolls down the page. However, I am currently facing an issue where the colors are not registering inside the ('') and the navbar remains white (#ffffff) regardless ...

Troubleshooting the 'npm ERR! ERESOLVE could not resolve' and 'peer dependency' issues: A guide to fixing the ERESOLVE error in npm

After several days of encountering an error while trying to set up a website for remote training, I have not been able to find a solution that fits my needs. Requesting your help to resolve the issue and get the site live on Vercel. Thank you in advance f ...

What is the best way to retrieve the session token in a route handler when utilizing NextAuth in the file api/generate/route.ts?

I am trying to obtain the session token within a route handler using NextAuth after successfully logging in with GoogleProvider. How can I access the session or token within my backend? api/generate/route.ts: import { getServerSession } from "next-au ...

Encountering a Hydration Error with Next.JS and MDX-Bundler when a MDX Component Adds Extra New Lines to its Children

Currently, I am incorporating next.js + mdx-bundler into my project. There is a simple component that I frequently use in my mdx files. Everything runs smoothly with the following code: Mdx is a great <Component>format and I like it a lot</Compon ...

Guide for animating individual mapped elements in react-native?

After mapping an object array to create tag elements with details, I added an animation for the tags to zoom in on render. However, I wanted to take it further and animate each tag individually, sequentially one after the other. This appears to be a common ...

What is the best method to incorporate a JavaScript object key's value into CSS styling?

I am currently working on a project in React where I'm iterating over an array of objects and displaying each object in its own card on the screen. Each object in the array has a unique hex color property, and my goal is to dynamically set the font co ...

Is there a way to modify the characteristics of a specific dependency?

I'm currently in the process of learning how to use the npm library, and came across this carousel. I successfully integrated it into my project, but now I find myself unsure about modifying its attributes. For reference, here's the documentation ...

Error Encountered in NextJS - Hydration Unsuccessful

Currently, I am utilizing NextLink in my project to generate links. However, it appears that using NextLink is causing the following error: Hydration failed because the initial UI does not match what was rendered on the server. Upon inspecting the console ...

Error: Requested URLs must be absolute and valid

Encountering an error while using the latest version of openid-client in a next-js application. Unhandled Runtime Error TypeError: only valid absolute URLs can be requested 3 | 4 | const oidcConfig = async () => { > 5 | const issuer = await I ...

What is the best method to retrieve the transloadit final link stored on a file's storage server (such as Google Cloud Storage) and bring it back to the component?

Trying to understand how to retrieve the final link stored in Google Storage (starting with "https://storage.googleapis.com/...") within a React component, but finding the documentation unclear. Even after successful file upload, I keep receiving "ASSEMBL ...

What is causing class-validator decorators to delete properties when combined with class-transformer?

I am exploring the use of class-validator and class-transformer for validating API requests in a Next.js API route. Below is a simple API handler setup to showcase this: import { plainToInstance } from 'class-transformer'; import { IsString } fr ...

The code coverage for the "rendering expectations" test in a particular component is insufficient

In order to test a specific component in my application, I am utilizing react-test-render. The test is intended to ensure that the component renders properly. Despite defining all the necessary properties for the component in the test file, the test cover ...

Ways to efficiently implement configuration settings in a functional approach

I've delved into the world of functional programming and I'm working on developing a package that needs to be configurable. My goal is to set up this configuration only once to maintain purity in my functions without relying on global state. Curr ...

No data is being recorded in the Firestore database

This component in nextjs is designed to write data to a firestore database after the user clicks a button. Unfortunately, Firebase seems to be having trouble writing the data, even though the alert message following the supposed data dump is successful. I ...

Sending data with React using POST request

Currently in my React application, I have a form that includes fields for username and password (with plans to add "confirm password" as well). When submitting the form, I need it to send JSON data containing the email and password in its body. The passwo ...

Is it possible to implement a Cross-Domain iframe Resizer in NextJS?

I am facing a challenge with my NextJS project that will be loaded within an Iframe. The page's content is dynamic, and its height changes frequently. Rather than relying on scrolling, I would like the Iframe to automatically adjust its height based o ...