Skip to content

Commit a1c8f2d

Browse files
Use attributes to props helper in DOM to React parser
1 parent 8b75b57 commit a1c8f2d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/dom-to-react.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Module dependencies.
55
*/
66
var React = require('react');
7+
var attributesToProps = require('./attributes-to-props');
78

89
/**
910
* Convert DOM nodes to React elements.
@@ -14,6 +15,7 @@ var React = require('react');
1415
function domToReact(nodes) {
1516
var result = [];
1617
var node;
18+
var props;
1719
var children;
1820

1921
for (var i = 0, len = nodes.length; i < len; i++) {
@@ -24,40 +26,38 @@ function domToReact(nodes) {
2426
continue;
2527
}
2628

29+
// update values
30+
props = attributesToProps(node.attribs);
2731
children = null;
2832

2933
// node type for script is "script" not "tag"
3034
if (node.name === 'script' && node.children[0]) {
3135
// prevent text in script tag from being escaped
3236
// https://facebook.github.io/react/tips/dangerously-set-inner-html.html
33-
node.attribs.dangerouslySetInnerHTML = {
37+
props.dangerouslySetInnerHTML = {
3438
__html: node.children[0].data
3539
};
3640

3741
} else if (node.type === 'tag') {
3842
// setting textarea value in children is an antipattern in React
3943
// https://facebook.github.io/react/docs/forms.html#why-textarea-value
4044
if (node.name === 'textarea' && node.children[0]) {
41-
node.attribs.defaultValue = node.children[0].data;
45+
props.defaultValue = node.children[0].data;
4246

4347
} else if (node.children) {
4448
// continue recursion of creating React elements
45-
children = domToReact(node.children);
49+
children = domToReact(node.children, options);
4650
}
4751
}
4852

4953
// specify a `key` prop if returning an array
5054
// https://fb.me/react-warning-keys
5155
if (len > 1) {
52-
node.attribs.key = i;
56+
props.key = i;
5357
}
5458

5559
result.push(
56-
React.createElement(
57-
node.name,
58-
node.attribs,
59-
children
60-
)
60+
React.createElement(node.name, props, children)
6161
);
6262
}
6363

0 commit comments

Comments
 (0)