Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have this error Expected to return a value at the end of arrow function consistent-return. Im not sure how I can prevent this.

Im trying to stop the Swiper carousel when the screen-size is below 1060px

    import Swiper from 'swiper';
    export default function () {
      let articlesGalleryCarousel;
      const doSomething = () => {
        const enableSwiper = () => {
          articlesGalleryCarousel = new Swiper('.js-swiper-container', {
            loop: true,
            slidesPerView: 'auto',
            centeredSlides: true,
            a11y: true,
            keyboardControl: true,
            grabCursor: true,
            pagination: '.swiper-pagination',
            paginationClickable: true,
            navigation: {
              nextEl: '.carousel-button--prev',
              prevEl: '.carousel-button--next',
        const breakpoint = window.matchMedia('(max-width:1060px)');
        const breakpointChecker = () => {
          if (breakpoint.matches === true) {
            if (articlesGalleryCarousel !== undefined) articlesGalleryCarousel.destroy(true, true);
          } else if (breakpoint.matches === false) {
            return enableSwiper();
        breakpoint.addListener(breakpointChecker);
        breakpointChecker();
      return doSomething;
                26:34  error  Expected to return a value at the end of arrow function  consistent-return  This is the error im getting
– Antony Moss
                Dec 28, 2018 at 15:30

ESLint is telling you that an arrow function should always or never return a value.

You have one branch that returns a value (return enableSwiper();) and one that doesn't (if breakpoint.matches is true).

So -- do you want that function to always return a value or to never return a value?

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.