diff --git a/example/src/App.js b/example/src/App.js index 5445629..9e31d8a 100644 --- a/example/src/App.js +++ b/example/src/App.js @@ -1,19 +1,26 @@ -import React from 'react' +import React, { useState } from 'react' import InnerHTML from 'dangerously-set-html-content' export default function App() { - const html = ` + const [content, setContent] = useState(`
This wil be rendered
- + ` + ) + const updatedHtml = ` +
Look at the console now!
+ ` return (
- + +
); } diff --git a/package.json b/package.json index 72e4c83..4b36fbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dangerously-set-html-content", - "version": "1.0.2", + "version": "1.0.3", "description": "Render raw html at your own risk!", "author": "christo-pr", "license": "MIT", diff --git a/src/index.js b/src/index.js index b002b7b..ebd9d7e 100644 --- a/src/index.js +++ b/src/index.js @@ -6,8 +6,9 @@ function DangerouslySetHtmlContent(props) { useEffect(() => { const slotHtml = document.createRange().createContextualFragment(html) // Create a 'tiny' document and parse the html string - divRef.current.appendChild(slotHtml) // Append it so it can be executed - }, []) + divRef.current.innerHTML = '' // Clear the container + divRef.current.appendChild(slotHtml) // Append the new content + }, [html]) return (