Skip to content

Commit 26f30c3

Browse files
chore(examples): add replace to nextjs
#1589
1 parent b956465 commit 26f30c3

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

examples/nextjs/pages/index.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Head from 'next/head';
2-
import parse from 'html-react-parser';
2+
import parse, { Element } from 'html-react-parser';
33

44
export default function Home() {
55
return (
@@ -10,10 +10,23 @@ export default function Home() {
1010

1111
<main>
1212
<h1 className="title">
13-
{parse(`
13+
{parse(
14+
`
1415
Welcome to <a href="https://nextjs.org">Next.js</a>
1516
and HTMLReactParser!
16-
`)}
17+
`,
18+
{
19+
replace(domNode) {
20+
if (domNode instanceof Element && domNode.name === 'a') {
21+
return (
22+
<a href="https://nextjs.org" rel="noopener noreferrer">
23+
Next.js
24+
</a>
25+
);
26+
}
27+
},
28+
},
29+
)}
1730
</h1>
1831
</main>
1932

0 commit comments

Comments
 (0)