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
An HTML to React parser that works on the server and the browser:
10
+
An HTML to React parser that works on both the server and the browser:
11
+
11
12
```
12
13
HTMLReactParser(htmlString[, options])
13
14
```
14
15
15
-
It converts an HTML string to [React elements](https://facebook.github.io/react/docs/react-api.html#creating-react-elements).
16
-
17
-
There's also an [option](#options) to [replace](#replacedomnode) elements with your own custom React elements.
16
+
The parser converts an HTML string to [React element(s)](https://reactjs.org/docs/react-api.html#creating-react-elements). If you want to [replace an element](#replacedomnode) with your own custom element, there's an [option](#options) to do that.
18
17
19
-
## Example
18
+
Example:
20
19
21
20
```js
22
-
var Parser =require('html-react-parser');
23
-
Parser('<p>Hello, world!</p>');
24
-
// same output as `React.createElement('p', {}, 'Hello, world!')`
21
+
var parse =require('html-react-parser');
22
+
parse('<div>text</div>'); // equivalent to `React.createElement('div', {}, 'text')`
The `replace` method allows you to swap an element with your own React element.
108
105
109
-
The first argument is `domNode`--an object with the same output as [htmlparser2](https://github.com/fb55/htmlparser2)'s [domhandler](https://github.com/fb55/domhandler#example).
106
+
The first argument is `domNode`―an object with the same output as [htmlparser2](https://github.com/fb55/htmlparser2)'s [domhandler](https://github.com/fb55/domhandler#example).
110
107
111
108
The element is replaced only if a valid React element is returned.
112
109
113
110
```js
114
-
Parser('<p id="replace">text</p>', {
111
+
parse('<p id="replace">text</p>', {
115
112
replace:function(domNode) {
116
113
if (domNode.attribs&&domNode.attribs.id==='replace') {
0 commit comments