Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
How to edit item in a Flatlist

I made a Flatlist and and edit button that can open a modal to a text input and track down the key of the specific item. How do I update this item in the Flatlist with the different text input. I tried doing something with the setJournal but I don't know how to return it with the edited entry.

export default function HomeScreen({ navigation }) {
  const [journal, setJournal] = useState([
    { date: "12-dec22", entry: "good day", key: "1" },
    { date: "12-dec22", entry: "bad day", key: "2" },
  ]);
  const [editModal, setEditModal] = useState(false);
  const handleEditPress = (key) => {
    const currentJournal = journal.find((journn) => {
      return journn.key === key;
    });
    setEditModal(true);
    console.log(key);
  };
  const updateEntry = (key, entry) => {
    if (journal.key === key) {
      setJournal((currentJournal) => {
        return [entry, ...currentJournal];
      });
    } else {}
    journal = journal.map((journn) =>
      journn.key === key ? { ...journn, ...updateEntry } : journn
    );
  };
  return (
    <View>
      <Modal visible={editModal}>
        <TextInput onChangeText={() => updateEntry()} />
        <MaterialIcons name="close" onPress={() => setEditModal(false)} />
      </Modal>
      <View>
        <MaterialIcons onPress={() => setModalOpen(true)}/>
        <MaterialIcons onPress={() => deleteAll()} />
      </View>
      <FlatList
        data={journal}
        renderItem={({ item }) => (
          <View style={styles.flatlistView}>
              <TouchableOpacity>
                <View>
                  <MaterialIcons onPress={() => handleEditPress(item.key)}/>
                </View>
              </TouchableOpacity>
          </View>
        )}
      />
    </View>
  );
}  
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

const handleEditPress = (editedField, itemKey)=>{

journal.filter((currentItem.key)=>{(currentItem.key) === itemKey})).text = editedField

setJournal(journal) }

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda