Conditionally adding rightIcon to ListItem
See original GitHub issueI’d like to add a rightIcon to a ListItem if the subtitle has a certain value (‘Notes’). I tried something like:
renderItem = ({ item }) => {
return (
<ListItem
title={item.title}
subtitle={item.subtitle}
topDivider
bottomDivider
{item.subtitle === 'Notes' &&
rightIcon={{ name: 'edit', type: 'material' }}
}
/>
);
};
but I get Parsing error: Unexpected token, expected "..."
Is my syntax wrong, or is this not possible?
I got it to work with a ternary that returns the whole ListItem with or without the rightIcon, but it’s more code duplication than I’d like, I’d like just the ListItem to be conditional.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
How to change rightIcon conditionally in List Item. I am using ...
() => this.changeIcon(item) returns a function reference but ListItem expects a component. try. rightIcon={this.changeIcon(item)}.
Read more >Conditionally Render Icon in List Item · Issue #715 - GitHub
Current behavior: I can't conditionally render icons in list items inside list. Expected behavior: Show icon on certain list items, and not on ......
Read more >Version 2.3 Upgrade Guide - React Native Elements
ListItem has been somewhat of a kitchen sink. All the props can be replaced by inserting them as children in the order of...
Read more >Components - NativeBase
Container comes with its predefined stylesheet, with an added advantage of ... Content, List, ListItem, Text, Left, Right, Icon } from 'native-base'; ...
Read more >How to write a list literal with conditional items? [duplicate]
Don't think this is a duplicate because I'm not asking about adding items to a list. Rather, how to declare a list. Also...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@iRoachie Thank you so much. I believe I need to learn more about the
...operator. 😃(By the way, I decided that I prefer the
nullapproach, it’s more readable in that it keepsrightIconaligned to the left with the other props…)