Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not access splide instance with ref.current.splide in Nextjs #77

Open
2 tasks done
sniperyork opened this issue Feb 7, 2024 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working

Comments

@sniperyork
Copy link

Checks

Version

0.7.12

Description

I try to display a list of cards in two rows, controlled by a filter system that updates based on user selection. However, I'm encountering difficulty displaying the data in two rows. It reverts to one row after each update. I suspect this may be due to an issue with the useEffect hook. I tried to access the Splide instance using a ref, but encountered a problem: the refresh() method is not available for the Splide instance. Instead, I receive a type error stating,

"Property 'splide' does not exist on type 'never'."

Can anyone give me some pointers please? below is a shorter version of my code:

const ref = useRef(null)

  useEffect(() => {
    filterData(categories);
    if (ref.current) {
      ref.current.splide.refresh();
    }
  }, [categories]);


        <Splide
          ref={ref}
          hasTrack={false}
          aria-label="cards"
          extensions={{ Grid }}
          className="flex w-full flex-col space-y-[2%] overflow-visible"
          options={{
            perPage: 4,
            gap: "1vw",
            arrows: false,
            pagination: true,
            drag: "free",
            snap: true,
            grid: {
              rows: 2,
              cols: 1,
              gap: {
                row: "1vw",
              },
            },
            padding: {
              right: "5%",
              left: "5%",
            },
          }}
        >
          <SplideTrack>
            {Cards.map((item: any) => {
              const {
                id,
                thumbnail_url
              } = item;
              return (
                <SplideSlide key={id}>
                  <Card
                    thumbnail_url={thumbnail_url}
                    onClick={() => handlePlanChange(id)}
                  />
                </SplideSlide>
              );
            })}
          </SplideTrack>

          <ul className="splide__pagination !bottom-[-4vh] space-x-[.4vw]" />
        </Splide>

Reproduction Link

No response

Steps to Reproduce

  1. create a ref using useRef
  2. attach the ref to the Splide jsx component
  3. create a useEffect hook and follow the instruction on the offcial splide for react document
  4. enter ref.current.splide.refresh() in useEffect and observe result
    ...

Expected Behaviour

display data in two rows

@sniperyork sniperyork added the bug Something isn't working label Feb 7, 2024
@bradleyDouglas
Copy link

@sniperyork Ever figure this out? I'm running into the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants