-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warns on access of props.key
and props.ref
#5744
Warns on access of props.key
and props.ref
#5744
Conversation
Link to SO could be change to a note in the docs |
props.key
and props.ref
props.key
and props.ref
'in `undefined` being returned. If you need to access the same ' + | ||
'value within the child component, you should pass it as a different ' + | ||
'prop. (http://stackoverflow.com/questions/33682774/how-to-access-the' + | ||
'-key-property-from-a-reactjs-component)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link explains about accessing key
and not ref
. Might be confusing to the reader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. The idea is to replace it with a link to relevant documentation being discussed at #5740
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR needs more work too. Its failing some tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally use fb.me urls that point to gists. I created one for you to use: https://fb.me/react-special-props
'%s: `key` is not a prop. Trying to access it will result ' + | ||
'in `undefined` being returned. If you need to access the same ' + | ||
'value within the child component, you should pass it as a different ' + | ||
'prop. (http://stackoverflow.com/questions/33682774/how-to-access-the' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
63a3ea8
to
f861879
Compare
@prometheansacrifice updated the pull request. |
props.key
and props.ref
props.key
and props.ref
@jimfb This PR is ready to be reviewed. Can you please have a look? |
'prop. (https://fb.me/react-special-props)', | ||
'displayName' in type ? type.displayName: 'Element' | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's explicitly add a return
statement here. This is a getter, so we should return a value, and it makes the expected behavior a little more clear. Same with the getter for ref
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I'll wait for @spicyj's comment on the next line note and update this PR afterwards.
f861879
to
55607a8
Compare
@prometheansacrifice updated the pull request. |
@prometheansacrifice Can you add an explicit return statement as per above, and then I think this is ready to go. |
@jimfb Sure |
Don't forget to add it to both getters (key+ref), even though I just called out one of them. |
55607a8
to
c3980a6
Compare
@prometheansacrifice updated the pull request. |
This looks great, thanks @prometheansacrifice! |
…es-key-ref-props Warns on access of `props.key` and `props.ref`
Calls to props.ref will throw a warning in React v15. This commit hard-codes the value instead of reading props.ref. The iconButtonRef element has been removed from the state object, since it never changes after the component is initialized. React warnings discussed in this PR: facebook/react#5744
Attempt for fix 5742