Skip to content

Commit e18cf81

Browse files
Update README with the key parameter in replace removed
1 parent b86a350 commit e18cf81

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

README.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,16 @@ ReactDOM.render(
6868

6969
### Options
7070

71-
#### replace(domNode, key)
71+
#### replace(domNode)
7272

7373
The `replace` method allows you to swap an element with your own React element.
7474

75-
The method has 2 parameters:
75+
The method has 1 parameter:
7676
1. `domNode`: An object which shares the same schema as the output from [htmlparser2.parseDOM](https://github.com/fb55/domhandler#example).
77-
2. `key`: A number to keep track of the element. You should set it as the ["key" prop](https://fb.me/react-warning-keys) in case your element has siblings.
7877

7978
```js
8079
Parser('<p id="replace">text</p>', {
81-
replace: function(domNode, key) {
80+
replace: function(domNode) {
8281
console.log(domNode);
8382
// { type: 'tag',
8483
// name: 'p',
@@ -88,8 +87,6 @@ Parser('<p id="replace">text</p>', {
8887
// prev: null,
8988
// parent: null }
9089

91-
console.log(key); // 0
92-
9390
return;
9491
// element is not replaced because
9592
// a valid React element is not returned
@@ -106,14 +103,13 @@ var React = require('react');
106103
var html = '<div><p id="main">replace me</p></div>';
107104

108105
var reactElement = Parser(html, {
109-
replace: function(domNode, key) {
106+
replace: function(domNode) {
110107
if (domNode.attribs && domNode.attribs.id === 'main') {
111108
return React.createElement('span', {
112-
key: key,
113109
style: { fontSize: '42px' } },
114110
'replaced!');
115111
// equivalent jsx syntax:
116-
// return <span key={key} style={{ fontSize: '42px' }}>replaced!</span>;
112+
// return <span style={{ fontSize: '42px' }}>replaced!</span>;
117113
}
118114
}
119115
});

0 commit comments

Comments
 (0)