Severity: warning | Blocks morph build: no
Status: documented rule —
morph checkdoes not report this code yet. The underlying problem still breaks your build or your UI; the cause and fix below apply when you hit it.
A key prop appears on an element that is not the root of a .map()
list template:
warning : mx-key-misuse : `key` is only meaningful inside `.map()` lists
hint: Remove `key` here, or move it to the list item root
Learn more: https://morph.levizr.com/docs/errors/mx-key-misuseThis is a warning: the build proceeds and key is ignored outside lists.
key exists for one job: letting list reconciliation match old items to new
items when an array changes (see mx-list-key). Outside a
.map() template there is no reconciliation — nothing ever compares keys —
so the prop does nothing. Its presence almost always means the author thought
key was passed to the component as data (it is not — key is stripped
before props, like React) or pasted it in the wrong place.
// ⚠️ key does nothing here — mx-key-misuse
export default function App() {
return (
<div>
<button key="save-btn" onClick={() => console.log("hi")}>Save</button>
</div>
);
}Remove the stray key, or move it where reconciliation actually runs:
// ✅ No key outside lists
export default function App() {
return (
<div>
<button onClick={() => console.log("hi")}>Save</button>
</div>
);
}// ✅ key belongs on the list item root
export default function App() {
const items = ["a", "b"];
return (
<div>
{items.map((item) => (
<div key={item}>{item}</div>
))}
</div>
);
}If you need an identifier inside the component, pass a real prop
(id="save-btn") — key never reaches component code.
Steps:
key from non-list elements, replacing it with id or a custom
prop if you needed the value.key only on the root element inside .map() callbacks.morph check.Safe to suppress per-file while prototyping, but the warning is pointing at dead markup — removing it is better:
{
"lint": {
"disable": ["mx-key-misuse"]
}
}key