This.key in React.js 0.12

前端 未结 1 1700
星月不相逢
星月不相逢 2021-01-03 17:55

With the release of version 0.12 this.props.key is no longer available inside a component, however it sounds like you can simply replace that with this.ke

相关标签:
1条回答
  • 2021-01-03 18:23

    What the docs actually recommend (although it's badly worded) is that you should treat key and ref as internal to React and not accessible inside the component. If you need to know the key, simply pass it as another property with a different name and then access it on this.props as 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 from above:

    You can no longer access this.props.ref and this.props.key from inside the Component instance itself. So you need to use a different name for those props.

    An example would be:

    <MyComponent key={foo} reactKey={foo} />
    

    Then accessing inside as this.props.reactKey.

    0 讨论(0)
提交回复
热议问题