Skip to content

Commit

Permalink
fix(bbob-react): remove unique "key" prop warning (#30)
Browse files Browse the repository at this point in the history
When using `@bbob/react`s `<BBCode>` component, the following error is thrown
if this change is not included...

```
Warning: Each child in a list should have a unique "key" prop.
```

Mentioned in #28
  • Loading branch information
skipjack authored and JiLiZART committed Jun 29, 2019
1 parent aac6358 commit 3d5c1f1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/bbob-react/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ const toAST = (source, plugins, options) => core(plugins)
render: input => html.render(input, { stripTags: true }),
}).tree;

function tagToReactElement(node) {
function tagToReactElement(node, index) {
return React.createElement(
node.tag,
node.attrs,
{ ...node.attrs, key: index },
// eslint-disable-next-line no-use-before-define
node.content ? renderToReactNodes(node.content) : null,
);
}

function renderToReactNodes(nodes) {
const els = [].concat(nodes).reduce((arr, node) => {
const els = [].concat(nodes).reduce((arr, node, index) => {
if (isTagNode(node)) {
arr.push(tagToReactElement(node));
arr.push(tagToReactElement(node, index));
} else if (isStringNode(node)) {
arr.push(node);
}
Expand Down

0 comments on commit 3d5c1f1

Please sign in to comment.