-
Notifications
You must be signed in to change notification settings - Fork 59
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
ref vs key #129
Comments
If the intention is to match React's API, then I would think it should be something like this: When returning an array of
P.S. I'm not saying this IS currently how the API works, but it's what I would expect if I was a React developer looking at Metal. |
@mthadley you got it right, that's exactly it. Basically As for example number |
Yes, react currently does allow refs for elements and they specify all refs on So for iterating through multiple components, do we use both ref and key? <div>
{
items.map(
item => (
<SomeComponent data={item} key={item.id} ref={item.id} />
)
)
}
</div> |
If it's just an iteration you'd only need |
I think this is something we are running into right now, though its not a huge issue currently because we can use key's as well. But in the future I can see it becoming an issue. I think changing matching logic to be based on parent elements would be of great benefit. Let us know what you find out and let us know if we can help in anyway. |
This issue was moved to #5 |
This issue was moved back. |
I've finished this change, it's available on version 2.0.0 now. |
the answer is exactly what I am looking for! thanks @mthadley ! |
I have been getting a little mixed up on the differences between these two and when to use each.
So those are a few cases above that seem strange.
I understand that
this.components
provides reference to the instance of the child components but I would expect to be able to reference any element in that manner.The biggest confusion for me is example (2). When iterating through a list and rendering multiple components, should I use
key
orref
? For a standard html element, I would always usekey
.From using metal, I would hope to be able to use
ref
to reference both elements and components. And then forkey
I would only use that when I am iterating inside of a parent component. Which also brings to mind this previous conversation. I am starting to think more so that components should be keyed based on their parent element, rather than their parent component.This is more so an open-ended issue, not necessarily a bug. Just a little confused on API and hoping to either clarify the actual API or set some rules on how to use key vs ref.
Let me know what you think! Thanks
The text was updated successfully, but these errors were encountered: