13

React 获取key 失败

 3 years ago
source link: https://segmentfault.com/a/1190000040001455
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

React 获取key 失败

发布于 今天 08:02
English

在组件中获取 this.props.key 将得到 undefined

大部分 JSX 元素上的 props 都会被传入组件,然而有两个特殊的 props (refkey) 已经被 React 所使用,不会被传入组件。

用一个不同的 prop 传入 <ListItem key={result.id} id={result.id} />。虽然这似乎是多余的,但是将应用程序逻辑和协调提示(reconciliation hints)分开是很重要的。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK