Python Mutable Defaults: Why a List Can Remember an Earlier Call
A Python function with a list as its default argument can behave as though it remembers a previous call. The list is…
A list item can move while still representing the same thing. React uses keys to identify items among their siblings. Choosing a key based only on position can cause confusing behaviour when items are inserted, removed or reordered.
Imagine three tasks with their own stable IDs and a text input in each row. A user edits the second task, then another task is inserted at the top. The previous positions have shifted. You want the row’s identity to follow the task, not whichever item now happens to be second.
{tasks.map(task => (
<TaskRow key={task.id} task={task} />
))}
React’s list guide recommends a stable key based on the data. Random values generated during rendering also fail to preserve identity. The key is a React hint and is not passed to the child as an ordinary prop; pass a separate ID if the component needs it.
Do not stop at “React needs a key to remove a warning”. Describe what each row represents and how its identity survives a change in ordering. For Malta frontend interviews, a small behaviour-based example is easier to assess than repeating a rule without understanding what it protects.
Explore software, cloud and data roles that fit your skills and ambitions.
Explore opportunitiesA Python function with a list as its default argument can behave as though it remembers a previous call. The list is…
Two Java objects can describe the same business item without being the same object in memory. Before discussing equals and hashCode in…
An async operation may no longer be needed because a user leaves a screen or a time limit is reached. In C#,…