-1

Unhandled Runtime Error TypeError: Cannot read properties of undefined (reading 'navigation')

onSwiper={(swiper) => {
            setTimeout(() => {
              swiper.params.navigation.prevEl = navigationPrevRef.current;
              swiper.params.navigation.nextEl = navigationNextRef.current;
              swiper.navigation.destroy();
              swiper.navigation.init();
              swiper.navigation.update();
            });
          }
Aidana
  • 1

2 Answers2

1

This error means that swiper or swiper.params is undefined and navigation cannot be read from it.

You can check it by adding a console.log(swiper) and console.log(swiper.params) before the setTimeout.

ChamRun
  • 104
  • 6
0

Add A If Condition it worked for me

setTimeout(() => {
            // Override prevEl & nextEl now that refs are defined
            if (swiper.params) {
              swiper.params.navigation.prevEl = navigationPrevRef.current;
              swiper.params.navigation.nextEl = navigationNextRef.current;

              // Re-init navigation
              swiper.navigation.destroy();
              swiper.navigation.init();
              swiper.navigation.update();
            }
          }, 500);
Saad khan
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 11 '23 at 00:30