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
Require key
prop in array comprehensions
#1348
Comments
Slight tangent, but React insists on throwing a warning whenever you use a key that is simply the index of the object being displayed. I would suggest we don't do that in Yew, since sometimes (even in React) the developer has no choice as the index is the only thing that would indicate continuity of the element being rendered. |
Isn't this contradicting the point of requiring the Perhaps there's a way for Yew to identify situations where a key makes sense and only warn the user about those situations? |
It may perhaps be functionally equivalent behavior, but explicitly requiring the developer to set a |
Having the user explicitly set the |
Could we enforce it with a compile time error, plus a "quick hack" escape hatch similar to lint ignores? Then we could disallow those escape hatches for production builds but allow it + emit a warning for dev builds. |
This should be possible using |
I think not all lists immediately deserve a warning for not using keys, or at least such a lint should be in the pedantic category. Two situations come to mind that are almost never false positives:
Requiring keys everywhere is, as said before, overkill and will lead to a lot of false positives and I'd only include it if there's a pedantic error category and at least part of the view function generates "dynamic" layout instead of always the same order of child components/elements. |
Problem
Per #1345, a key prop should be provided whenever there is an array of children elements. We do not currently see an error or warning when one is not provided.
Questionnaire
The text was updated successfully, but these errors were encountered: