christo-pr / dangerously-set-html-content

Render raw html at your own risk! v2
60 stars 8 forks source link

Small fix for scripts running twice #7

Closed HamzaAbugazia closed 1 year ago

HamzaAbugazia commented 1 year ago

I noticed that the useEffect that sets the div's inner HTML was running twice. This is fine for the content being rendered, since the innerHTML is cleared. but the script tags run twice, causing some issues in our use-case.

This is a very simple hack to stop that from happening.

christo-pr commented 1 year ago

Thanks @HamzaAbugazia , maybe this is due to React 18 useEffect and Strict Mode, so I wouldn't expect to affect any production env, but certainly can cause issues while development.

I think we can use this hack for now