You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-50Lines changed: 7 additions & 50 deletions
Original file line number
Diff line number
Diff line change
@@ -104,64 +104,21 @@ render(
104
104
105
105
#### replace(domNode)
106
106
107
-
The `replace` method allows you to swap an element with your own React element.
107
+
The `replace` method allows you to swap an element with your own React Element.
108
108
109
-
The first argument is `domNode`, which is an object which shares the same schema as the output from[htmlparser2.parseDOM](https://github.com/fb55/domhandler#example).
109
+
The first argument is `domNode`, which is an object that has the same output as[htmlparser2.parseDOM](https://github.com/fb55/domhandler#example).
110
110
111
-
```js
112
-
Parser('<p id="replace">text</p>', {
113
-
replace:function(domNode) {
114
-
console.log(domNode);
115
-
// { type: 'tag',
116
-
// name: 'p',
117
-
// attribs: { id: 'replace' },
118
-
// children: [],
119
-
// next: null,
120
-
// prev: null,
121
-
// parent: null }
122
-
123
-
return;
124
-
// element is not replaced because
125
-
// a valid React element is not returned
126
-
}
127
-
});
128
-
```
129
-
130
-
Simple example:
111
+
The element is only replaced if a valid React Element is returned.
131
112
132
113
```js
133
-
var Parser =require('html-react-parser');
134
-
var React =require('react');
135
-
136
-
var html = (
137
-
'<div>'+
138
-
'<p id="replace">'
139
-
'replace me'+
140
-
'</p>'+
141
-
'</div>'
142
-
);
143
-
144
-
var reactElement =Parser(html, {
145
-
replace:function(domNode) {
114
+
// with JSX
115
+
Parser('<p id="replace">text</p>', {
116
+
replace: (domNode) => {
146
117
if (domNode.attribs&&domNode.attribs.id==='replace') {
0 commit comments