-3

I'm working on trying to only render a header when a collections is present and to not render it when it is empty. A simple fix but I've been receiving this Unexpected Token syntax error and I can't seem to find the issue. Any help would be greatly appreciated as this is my first time posting and using 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>
);
Jordan Running
  • 102,619
  • 17
  • 182
  • 182
pdphiro
  • 5
  • 2

1 Answers1

0

You need to remove brackets in ternary operator to validate your js at first:

const collectionsHeaderHandler = ({ favorites }) =>
favorites.meta.collections ?
copyDek.FavoritesLayout.collectionsHeader :
"";

Edit for reduce linter error

const FavoritesLayoutCollections = ({ favorites, onPressHandlers }) => (
 <FavoritesLayoutCollectionsWrapper>
   <FavoritesLayoutCollectionsHeader>
     {collectionsHeaderHandler({favorites})}
   </FavoritesLayoutCollectionsHeader> 
   <FavoritesCollections
     collections={favorites.meta.collections}
     onPressCollection={onPressHandlers.onPressCollection}
   />
 </FavoritesLayoutCollectionsWrapper>
);
Artem Mirchenko
  • 2,140
  • 1
  • 9
  • 21
  • Was able to get rid of the syntax errors, but now I have a `no-unused-expressions` error. I don't know if its because of my condition. The `favorites.meta.collections` condition is supposed to check if it exists or not, and if it doesn't return empty, but the code doesn't seem to be following that logic. Looking through how I can change my condition, any tips would be great! – pdphiro Apr 03 '18 at 20:22
  • @Ernie Hao no-unused-expressions it is ok, it is linter error, https://eslint.org/docs/rules/no-unused-expressions its mean that you declare expression but not used it in you follow code. – Artem Mirchenko Apr 03 '18 at 20:25
  • @Ernie Hao I edit my answer to reduce no-unused-expressions error, try to run the code. – Artem Mirchenko Apr 03 '18 at 20:30
  • Hey Artem. I implemented the function call with `favorites` in `FavoritesLayoutCollections` but im still receiving no-unused-expressions. Ill be looking into it more. Thank you so much! Any more other recommendations? – pdphiro Apr 03 '18 at 20:40
  • @Ernie Hao Okay, maybe there is enywhere else in code present no-unused, you can reed the liner docs and maybe this help fixed your linter warnings. good luck) – Artem Mirchenko Apr 03 '18 at 20:44
  • Yeah I think so too. You've been a great help. Best! – pdphiro Apr 03 '18 at 20:45