Fiddle: correction for child keys in markdown component#229
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes React key prop warnings in the Markdown component by ensuring all children in the MarkdownBulletText component have proper keys. The changes add the index parameter to the map function and use it as a fallback when child.key is not available.
Key Changes:
- Added
indexparameter toReact.Children.toArray().map()callback - Used
indexas the key for string children and as a fallback (child.key ?? index) for React element children
Comment on lines
+82
to
+84
| return React.cloneElement(child, { isInline: true, key: child.key ?? index }); | ||
| } | ||
| return React.cloneElement(child, { key: child.key }); | ||
| return React.cloneElement(child, { key: child.key ?? index }); |
There was a problem hiding this comment.
The eslint-disable-next-line react/no-array-index-key comment is only applied to line 77, but lines 82 and 84 also use index as a fallback for the key prop. For consistency, either apply the same eslint-disable comment to these lines or remove it from line 77 if using index as a fallback is acceptable throughout this function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Screenshots:
Checklist: