question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ListItem rightTitle propType should be PropTypes.any(or object) instead of PropTypes.string

See original GitHub issue

Description

I’m not a expert of React and RN, so It could be my mistake.

If it isn’t a bug or a issue, close this issue please.

When using nested Text components for the rightTitle prop of ListItem, I get a PropTypes warning because it expects only a string. The underlying TextElement component allows its children to be PropTypes.any, so shouldn’t the ListItem allow rightTitle to be PropTypes.any also?

I’m using version 0.17.0

Reproduction Steps and Sample Code


const rightTitle = (
    <View width={50} height={20}>
        <Text>{Title}</Text>
        <Text>{Subtitle}</Text>
    </View>
)
<ListItem ... otherProps rightTitle={rightTitle} />

Solution

it could just change the propType of rightTitle to PropTypes.any in ListItem.js.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
iRoachiecommented, Mar 4, 2018

It’s a feature that should be added in v1 of our library. Right now the ListItem component is being completely rewritten to be more flexible. Can see the progress here.

Should be released with beta4 https://github.com/react-native-training/react-native-elements/milestone/2

2reactions
wkwyattcommented, Mar 4, 2018

@iRoachie well here is a workaround until the component gets added if you need a subtitle for the rightTitle.

<ListItem
    title="Title"
    subtitle="Subtitle"
    onPress={() => doSomething()}
    hideChevron
    label={
        <View style={{flexDirection: 'row'}}>
            <View style={{flexDirection: 'column'}}>
                <Text>Right Title</Text>
                <Text>Right Subtitle</Text>
            </View>
            <Icon
                name="chevron-right"
                size={14} color="#000"
                style={{paddingHorizontal: 20, backgroundColor: 'transparent',  alignSelf: 'center'}}
            />
       </View>
   }
/>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Typechecking With PropTypes - React
To run typechecking on the props for a component, you can assign the special propTypes property: import PropTypes from 'prop-types'; class Greeting extends ......
Read more >
Allow different types of PropTypes for one prop - Stack Overflow
I have a component that receives a prop for its size. The prop can be either a string or a number ...
Read more >
How to validate React props using PropTypes - LogRocket Blog
Learn how to validate props with React PropTypes, React's internal mechanism for adding type checking to component props.
Read more >
How To Use PropTypes In React - Web Dev Simplified Blog
The most basic way you can check a prop's type is by checking to see if it is one of the primitive types...
Read more >
How to Use PropTypes in React - freeCodeCamp
We can use PropTypes to validate any data we are receiving from props. ... String. PropType.string. “helllo”. Object. PropType.object.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found