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

162
Views
Estoy tratando de eliminar una nota en reaccionar, pero recibo un error que indica que no puede acceder a nuevas notas antes de la inicialización.

Reaccionar Encuentre un error en la función de eliminación de notas que no puede acceder a las nuevas notas antes de la inicialización, ¿por eso no se puede eliminar esa nota?

La función deleteNote está funcionando porque su consola registra el mensaje con la identificación que escribí en él, pero no elimina la nota, ya declaré la nueva nota e inicié el valor en ella, pero no puedo entender por qué dio el error. ?

 const [notes, setNotes] = useState(notesInitial) //Add Note const addNote = (title, description, tag) => { //TODO API CALL console.log("adding a new note"); const note = { "_id": "63074e71318fac99be7ce65a", "user": "62ee8f0b86e5c4946d3b75d5", "title": title, "description": description, "tag": tag, "date": "2022-08-25T10:26:57.324Z", "__v": 0 }; setNotes(notes.concat(note)); } //Delete A Note const deleteNote = (id) => { console.log("The node delteing with id" + id); I think I missing something here const newNotes = newNotes.filter((notes) => { return notes._id !== id }) setNotes(newNotes); } return ( <noteContext.Provider value={{ notes, addNote, deleteNote, editNote }}> {props.children} </noteContext.Provider> ) } export default NoteState;
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

sí, cometiste un error aquí, así que conviértelo de

 //Delete A Note const deleteNote = (id) => { console.log("The node delteing with id" + id); I think I missing something here const newNotes = newNotes.filter((notes) => { return notes._id !== id }) setNotes(newNotes); }

a

 const deleteNote = (id) => { console.log("The node delteing with id" + id); I think I missing something here const newNotes = notes.filter((note) => { return note._id !== id }) setNotes(newNotes); }
about 4 years ago · Juan Pablo Isaza Report

0

const newNotes = newNotes.filter((notes) => { return notes._id !== id })

newNotes se declaran nuevamente y no se tomarán de su estado de useState . En la función deleteNode , asígnele el nombre de cualquier otra cosa.

 const deleteNote = (id) => { console.log("The node delteing with id" + id); I think I missing something here const newNotes2 = notes.filter((notes) => { return notes._id !== id }) setNotes(newNotes2); }
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!