admin管理员组文章数量:1356467
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;
}
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;
}
Share
Improve this question
asked Dec 28, 2018 at 15:29
Antony MossAntony Moss
1872 gold badges2 silver badges8 bronze badges
1
-
26:34 error Expected to return a value at the end of arrow function consistent-return
This is the error im getting – Antony Moss Commented Dec 28, 2018 at 15:30
2 Answers
Reset to default 4This is an ESLint consistent-return warning.
"This rule requires return statements to either always or never specify values"
Your function "breakpointChecker" did not returns something in case of the first IF statement.
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?
本文标签: javascriptExpected to return a value at the end of arrow function errorStack Overflow
版权声明:本文标题:javascript - Expected to return a value at the end of arrow function error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744004926a2574525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论