Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
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 Respostas
Responde à pergunta

0

const handleEditPress = (editedField, itemKey)=>{

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

setJournal(journal) }

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda