react native onscroll api call code example

Example: 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>
  );
}