Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
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 answers
Answer question

0

const handleEditPress = (editedField, itemKey)=>{

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

setJournal(journal) }

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!