React Native Add Items To FlatList Dynamically using TextInput on Button Click

FlatList is one of the most usable component in react native, it’s the uppermost version of ListView and used to display a Items of list on mobile screen. In Today’s tutorial we would make a react native application with TextInput, Button and FlatList component. We would enter the values of TextInput inside the FlatList dynamically on button onPress event. So in this tutorial we would going to Add Items To FlatList Dynamically using TextInput on Button Click in react native android iOS application example tutorial.

Contents in this project Add Items To FlatList Dynamically using TextInput on Button Click Android iOS React Native App:

1. Import StyleSheet, FlatList, Text, View, Alert, TouchableOpacity and TextInput component in your project.

2. Create constructor() in your project’s main class.

this.array : Is our main array in which would simply add some default values for the FlatList.

this.state. arrayHolder : Its the State array. We would use this array to show data into FlatList first we would copy the this.array into this.state. arrayHolder state and using the arrayHolder state we would show the data on FlatList.

this.state.textInput_Holder : It is used to hold the typed data from TextInput component.

3. Creating  componentDidMount() method in your main class. Now inside this method we would simply copy the this.array into arrayHolder State. Here is three dot is the array destructive operator

4. Creating a function named as joinData() in your class, Inside this function we would first PUSH(Enter) the value coming from TextInput component inside this.array and then we would simply copy the this.array into arrayHolder state.

5. Creating a function named as FlatListItemSeparator(), This function would render a slim horizontal line between each item of FlatList.

6. Creating a function named as GetItem(), Using this function we would show the selected Item value of FlatList on screen.

7. Creating a TextInput, Touchable Opacity and FlatList component inside the render’s return block.

8. Creating Style.

9. Complete source code for App.js File :

Screenshots:

Add Items To FlatList Dynamically