In plain words
A callback is a function you pass to other code so it can call it later, like when a button is clicked or data arrives.
Where you see it
Every onClick in your React components takes a callback. In Quill, onClick={() => deleteNote(note.id)} hands the button a small function to run when Maya clicks, and not a moment before.
What goes wrong
- Calling the function instead of passing it
onClick={deleteNote(note.id)} runs deleteNote the moment the page draws, so notes vanish on load. Wrap it: () => deleteNote(note.id).
onClick={deleteNote(note.id)} - Callbacks nested five deep
Older-style code that tucks one callback inside another is hard to follow and easy to break. async/await does the same work and reads top to bottom.
- Expecting a callback to run straight away
setTimeout and event listeners run their callback later. The next line runs first, so a value set inside the callback isn't there yet.
What to tell your agent
Quick check
Sign in to earn +10 XP for itIn Quill, every note disappears as soon as the notes page loads. The delete button says onClick={deleteNote(note.id)}. Why?