react-bits:列表组件
发布时间:2020-12-15 07:26:23 所属栏目:百科 来源:网络整理
导读:react-bits 原文 不建议将列表内单个元素抽象出组件,建议使用map const SearchSuggestions = (props) = { // renderSearchSuggestion() behaves as a pseudo SearchSuggestion component // keep it self contained and it should be easy to extract later
react-bits 不建议将列表内单个元素抽象出组件,建议使用map const SearchSuggestions = (props) => {
// renderSearchSuggestion() behaves as a pseudo SearchSuggestion component
// keep it self contained and it should be easy to extract later if needed
const renderSearchSuggestion = listItem => (
<li key={listItem.id}>{listItem.name} {listItem.id}</li>
);
return (
<ul>
{props.listItems.map(renderSearchSuggestion)}
</ul>
);
};
如果组件变的更复杂或者你想在其他地方使用这个组件,建议复制粘贴到一个新的组件,不要过早使用组合。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |