react native infinite scroll flatlist code example
Example 1: react native flatlist horizontal scroll
<FlatList
horizontal
pagingEnabled={true}
showsHorizontalScrollIndicator={false}
legacyImplementation={false}
data={this.props.photos}
renderItem={item => this.renderPhoto(item)}
keyExtractor={photo => photo.id}
style={{width: SCREEN_WIDTH + 5, height:'100%'}}
/>
Example 2: make an infinite list in react native
export default function App() {
const [enteredGoal,setEnteredGoal] = useState('');
const [courseGoals, setCourseGoals] = useState([]);
const goalInputHandler = (enteredText) => {
setEnteredGoal(enteredText);
}
const addGoalHandler = () => {
setCourseGoals(currentGoals =>
[...currentGoals,{key:Math.random().toString(),value:enteredGoal}]
)
}
return (
<View style={styles.screen}>
<View>
<View style={styles.otherview}>
<TextInput
placeholder='A goal'
style={styles.textinput}
onChangeText={goalInputHandler}
value={enteredGoal}/>
<Button title='Add' onPress={addGoalHandler}/>
</View>
</View>
<FlatList
data={courseGoals}
renderItem={itemData => (
<View style={styles.listItem}>
<Text>{itemData.item.value}</Text>
</View>
)}
/>
</View>
);
}