在組件中獲取 this.props.key 將獲得 undefined。this
this.props.key
undefined
大部分 JSX 元素上的 props 都會被傳入組件,然而有兩個特殊的 props (ref 和 key) 已經被 React 所使用,不會被傳入組件。code
ref
key
用一個不一樣的 prop 傳入 <ListItem key={result.id} id={result.id} />。雖然這彷佛是多餘的,可是將應用程序邏輯和協調提示(reconciliation hints)分開是很重要的。ci
<ListItem key={result.id} id={result.id} />