javascript - This.key in React.js 0.12 -
with release of version 0.12 this.props.key
no longer available within component, sounds can replace this.key
, should work expected.
from react v0.12 docs:
this means need rename: someelement.props.key -> someelement.key
however when seek access this.key
within render() function of component, undefined
.
see pen illustrate issue: http://codepen.io/anon/pen/jaczr?editors=100
also:
instances of react component created internally in react when rendering. these instances reused in subsequent renders, , can accessed in component methods this.
how supposed access component's key?
update
there this issue on github clarifies lot. heap mentioning it.
what docs recommend (although it's badly worded) should treat key
, ref
internal react , not accessible within component. if need know key, pass property different name , access on this.props
normal.
http://facebook.github.io/react/blog/2014/10/16/react-v0.12-rc1.html#breaking-change-key-and-ref-removed-from-this.props
quote above:
you can no longer access this.props.ref , this.props.key within component instance itself. need utilize different name props.
an illustration be:
<mycomponent key={foo} reactkey={foo} />
then accessing within this.props.reactkey
.
javascript reactjs
No comments:
Post a Comment