gpt4 book ai didi

javascript - React 组件的 ESLint 规则 : Method Render expected no return value

转载 作者:行者123 更新时间:2023-11-29 16:05:01 25 4
gpt4 key购买 nike

我这辈子都无法理解为什么有人会想要这条规则,更不用说它意味着什么了。我在渲染中返回一些东西

export default class SearchTabs extends Component {
render() {
const { panels, selectedTab } = this.props;
if (!panels || panels.length === 0) return;

let filter = null;

const tabs = panels.member.map((panel, idx) => {
const { id: panelId, headline } = panel;
const url = getHeaderLogo(panel, 50);
const item = url ?
<img src={url} alt={headline} /> : headline;
const classname = classNames([
searchResultsTheme.tabItem,
(idx === selectedTab) ? searchResultsTheme.active : null,
]);

filter = (idx === selectedTab) ? this.renderFilters(panel) : filter;

return (
<TabItem
classname={`${classname} search-tab`}
headline={headline}
idx={idx}
content={item}
onclick={() => {
this.tabChanged(idx, headline);
}}
panelId={panelId}
/>
);
});

return (
<div className={searchResultsTheme.filters}>
<ul className={`${searchResultsTheme.tabs} ft-search-tabs`}>{tabs}</ul>
<div className={searchResultsTheme.dropdown}>{filter}</div>
</div>
);
}
}

最佳答案

我相信你的问题是线路

if (!panels || panels.length === 0) return;

它在提示,因为此代码路径不返回任何内容。尝试将其更改为

if (!panels || panels.length === 0) return null;

关于javascript - React 组件的 ESLint 规则 : Method Render expected no return value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45786965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com