Concepts

Reset state with a key

A different key at the same parent position can replace a component subtree and reset its local state.

Formal Syntax & Structure

react syntaxreact
<Note key={record.id} name={record.name} />

Working Example

Example Snippetreact
import { useState } from "react"; function Note({ name }) { const [draft, setDraft] = useState(""); return <label>{name}<input value={draft} onChange={e => setDraft(e.target.value)} /></label>; } function Editor({ record }) { return <Note key={record.id} name={record.name} />; }
React Reference