JavaScript Conditional Components in React Native conditional components react,conditional rendering components react

I'm new to working with React Native and I am wondering what the best way is to create a conditional component that will show when the user data has the field, and hides when it does not. Using education in this example.

import React, { Component } from 'react';
import { StyleSheet, Image, TouchableOpacity } from 'react-native';
import { Container, Content, Button, Icon, View, DeckSwiper, Card, CardItem, Thumbnail, Text, Left, Body} from 'native-base';

import styles from './style';

const cards = [
    {
        _id: 1,
        name: 'John Doe',
        age: 30,
        education: 'State University',
        occupation: 'Programmer',
        company: 'Acme Inc.',
        image: require('img.jpg')
    },
    {
        _id: 2,
        name: 'Jane Doe',
        age: 30,
        education: 'State University',
        occupation: 'Programmer',
        company: 'Acme Inc.',
        image: require('img.jpg')
    },
    {
        _id: 2,
        name: 'Jane Doe',
        age: 30,
        education: 'State University',
        occupation: 'Programmer',
        company: 'Acme Inc.',
        image: require('img.jpg')
    },
];

export default class Cards extends Component {

    constructor(){
        super();
        this.state = {
            showEdu: true
        }
    }

    render() {
        let edu = this.state.showEdu ? this.props.education : '';
        return (
            <Container>
                <View>
                    <DeckSwiper
                        dataSource={cards}
                        renderItem={item =>
                            <Card style={{ elevation: 3 }}>
                                <CardItem cardBody>
                                    <Image style={styles.cardImg} source={item.image} />
                                </CardItem>
                                <CardItem>
                                    <Icon name="heart" style={{ color: '#ED4A6A' }} />
                                    <Content>
                                        <Text>{item.name}, {item.age}</Text>
                                        <Text style={styles.profileText2}>{item.occupation}, {item.company}</Text>
                                        <Text style={styles.profileText2}>{item.education}</Text>
                                    </Content>
                                </CardItem>
                            </Card>
                        }
                    />
                </View>
            </Container>
        );
    }
}

module.export = Cards;
Answer:1

If I understand your question correctly, you want to know how to only display something if the property exists? Something like this should work.

{ item.education &&
    <Text style={styles.profileText2}>{item.education}</Text>
}
Answer:2

I have these two scripts, one sorts divs by a value in a div class (price) and the other shows or hides divs based on class name with buttons. (box a, box b etc, inside a "parent" class.) The problem ...

I have these two scripts, one sorts divs by a value in a div class (price) and the other shows or hides divs based on class name with buttons. (box a, box b etc, inside a "parent" class.) The problem ...

  1. hide show divs
  2. hide show divs jquery
  3. show hide divs javascript
  4. show hide divs on click
  5. show hide divs react
  6. show/hide div angularjs
  7. hide show onclick jquery
  8. hide show onclick javascript
  9. hide show onclick
  10. hide show multiple divs jquery
  11. hide show multiple divs javascript
  12. hide show multiple divs
  13. hide and show divs html
  14. hide and show divs bootstrap
  15. css hide show divs
  16. show hide onclick css
  17. onclick hide show div
  18. onclick hide show div jquery
  19. show hide multiple divs css
  20. css javascript hide show divs

For some reason I have to do this for(let i=0;i<=6;i++){ price.push({ min_price: `this.state.special_${i}_min`, max_price: `this.state.special_${i}_max` }); } But it's not ...

For some reason I have to do this for(let i=0;i<=6;i++){ price.push({ min_price: `this.state.special_${i}_min`, max_price: `this.state.special_${i}_max` }); } But it's not ...

I have an array that creates a conversation between two people where it 'flips' between the browser speaking and the browser listening. Short version, how do I make saySomething queue for(var i=0; ...

I have an array that creates a conversation between two people where it 'flips' between the browser speaking and the browser listening. Short version, how do I make saySomething queue for(var i=0; ...

  1. queue javascript events

I have a Node.js route that sends back some text and logs the request: app.post('/registerUser', function (req, res) { res.send('Hello World post!') console.log(req); }) Then I hit that route ...

I have a Node.js route that sends back some text and logs the request: app.post('/registerUser', function (req, res) { res.send('Hello World post!') console.log(req); }) Then I hit that route ...

  1. node inspect websockets request was expected
  2. inspect request node.js