-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add element's key
and ref
to tree and prop views
#328
Add element's key
and ref
to tree and prop views
#328
Conversation
Fixes facebook#148. Fixes facebook#226. If a `key` or `ref` is set on the React element, it's displayed before the `props` in the tree view and in the `PropState` sidebar. If none is set, nothing is changed. Also removed a piece of code `Node.js` that would never run. (condition is checked in the previous block that `return`s)
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! |
CLA signed. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
@spicyj any chance to get this looked at? Thanks! |
😐 |
@Timothee sorry to take so long on this. It looks great! one request: can you make it handle the "ref is a function" case gracefully? |
I suppose I've been using legacy code with regards to refs then 😄 @jaredly if |
Actually, re-reading #226:
but
I'll look into that last one a bit, but otherwise will just skip it if it's a function. (unless you have better ideas) |
that sounds fine to me! |
Refs as strings is the "old" way. They can also be functions and this should handle it nicely. They are already handled nicely in the main elements panel. However the sidebar only showed `[object Object]`. To make it work, I reused the `PropVal` element since it already manages styles for different types of values. This way, `key` and `ref` look like they do in the main panel. In particular, `PropVal` handles functions well: if they are named, they are replaced by `functionName()`, otherwise simply by `fn()`. This change also includes parsing `key` as a string, just in case.
@jaredly updated. Now the following JSX: var Container = React.createClass({
render: () => {
return (
<div>
<div key='withKey'>with a key</div>
<div ref='stringRef'>with a string ref</div>
<div ref={()=>{}}>with an unnamed function ref</div>
<div ref={function namedFn() {}}>with a named function ref</div>
<div key='withKeyAndRef' ref={function namedFn() {}}>with a named function ref and a key</div>
</div>
);
}
}); is shown like this: The replacement of the unnamed function into |
These `Props` can probably use a `key`, sitting like that in a row... Moving the triangle up a bit to line it up better with the text.
Oops.
Please merge this :) |
@jaredly bump 👀 |
This is in. Thank you so much! |
THANKS! |
Fixes #148.
Fixes #226.
If a
key
orref
is set on the React element, it's displayed beforethe
props
in the tree view and in thePropState
sidebar.If none is set, nothing is changed.
Also removed a piece of code
Node.js
that would never run. (conditionis checked in the previous block that
return
s)