mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-20 20:00:33 +03:00
fix(bbob-react): remove unique "key" prop warning (#30)
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
This commit is contained in:
committed by
Nikolay Kostyurin
parent
aac6358d53
commit
3d5c1f19d5
@@ -10,19 +10,19 @@ const toAST = (source, plugins, options) => core(plugins)
|
|||||||
render: input => html.render(input, { stripTags: true }),
|
render: input => html.render(input, { stripTags: true }),
|
||||||
}).tree;
|
}).tree;
|
||||||
|
|
||||||
function tagToReactElement(node) {
|
function tagToReactElement(node, index) {
|
||||||
return React.createElement(
|
return React.createElement(
|
||||||
node.tag,
|
node.tag,
|
||||||
node.attrs,
|
{ ...node.attrs, key: index },
|
||||||
// eslint-disable-next-line no-use-before-define
|
// eslint-disable-next-line no-use-before-define
|
||||||
node.content ? renderToReactNodes(node.content) : null,
|
node.content ? renderToReactNodes(node.content) : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderToReactNodes(nodes) {
|
function renderToReactNodes(nodes) {
|
||||||
const els = [].concat(nodes).reduce((arr, node) => {
|
const els = [].concat(nodes).reduce((arr, node, index) => {
|
||||||
if (isTagNode(node)) {
|
if (isTagNode(node)) {
|
||||||
arr.push(tagToReactElement(node));
|
arr.push(tagToReactElement(node, index));
|
||||||
} else if (isStringNode(node)) {
|
} else if (isStringNode(node)) {
|
||||||
arr.push(node);
|
arr.push(node);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user