Youwang Deng

I'm a software developer, familiar with C#, Java, JavaScript, focus on full stack development.

Dynamically Add elements in React Native

04 Jun 2019 » JavaScript, React-Native

Dynamically create elements in React Native

class Example extends React.Component {
    constructor(props) {
        super(props);
        this.dataExample = this.props.dataExample;
    }
    render() {
        let list = [];
        this.dataExample.forEach((e,i)=>{
            // need to add a key to each item in the list
            list.push(
                <View key={e + i}>
                    <Text>{e.title}</Text>
                </View>
            );
        });
        return (
            <View>
                {list}
            </View>
        );
    }
}