Neotrixs
Neotrixs

Reputation: 2537

Show <View> based on dynamic data in React-Nave?

I am new React-Native, I try to show some dynamic data inside View tag but I get an error: text strings must be rendered within a component.

        {someValue &&
            <View>
                <Card>
                    <CardItem header>
                        <View>
                            <Text>Result :{someValue}</Text>
                        </View>
                    </CardItem>
                    <CardItem>
                        <Body>
                            <View>
                                <Text>
                                    {someInfo}
                                </Text>
                            </View>
                        </Body>
                    </CardItem>
                </Card>
            </View>
        }

Please help me to find out my mistake. Thanks:)

Upvotes: 1

Views: 44

Answers (1)

Nooruddin Lakhani
Nooruddin Lakhani

Reputation: 6967

Here code looks someInfo value might bt empty or null, Try this way ( UPDATED )

<CardItem header>
  {someValue && someValue.length > 0 ? (
    <View>
      <Text>Result :{someValue}</Text>
    </View>
  ) : null}
</CardItem>

<View>{someInfo && someInfo.length > 0 ? <Text>{someInfo}</Text> : null}</View>

Upvotes: 1

Related Questions