我正在尝试仅在collections
存在时呈现标题,并在空白时不呈现标题。一个简单的修复,但我一直收到这个意外的令牌语法错误,我似乎无法找到问题。任何帮助将不胜感激,因为这是我第一次发布和使用react-native!
const collectionsHeaderHandler = ({ favorites }) =>
{favorites.meta.collections} ?
{copyDek.FavoritesLayout.collectionsHeader} :
"";
const FavoritesLayoutCollections = ({ favorites, onPressHandlers }) => (
<FavoritesLayoutCollectionsWrapper>
<FavoritesLayoutCollectionsHeader>
{collectionsHeaderHandler}
</FavoritesLayoutCollectionsHeader>
<FavoritesCollections
collections={favorites.meta.collections}
onPressCollection={onPressHandlers.onPressCollection}
/>
</FavoritesLayoutCollectionsWrapper>
);
答案 0 :(得分:0)
您需要删除三元运算符中的括号以首先验证您的js:
const collectionsHeaderHandler = ({ favorites }) =>
favorites.meta.collections ?
copyDek.FavoritesLayout.collectionsHeader :
"";
const FavoritesLayoutCollections = ({ favorites, onPressHandlers }) => (
<FavoritesLayoutCollectionsWrapper>
<FavoritesLayoutCollectionsHeader>
{collectionsHeaderHandler({favorites})}
</FavoritesLayoutCollectionsHeader>
<FavoritesCollections
collections={favorites.meta.collections}
onPressCollection={onPressHandlers.onPressCollection}
/>
</FavoritesLayoutCollectionsWrapper>
);