Answers for "make an infinite list in react native"

1

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>
  );
}
Posted by: Guest on May-20-2020

Code answers related to "make an infinite list in react native"

Code answers related to "Javascript"

Browse Popular Code Answers by Language