Skip to content

Commit

Permalink
bottle data tags are imgs
Browse files Browse the repository at this point in the history
  • Loading branch information
giannif committed Nov 1, 2024
1 parent f3dcc43 commit f10c7aa
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions packages/react-components/src/components/bottle-data.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { noUUIDRandom } from '@giphy/js-util'
import React, { useRef, useLayoutEffect } from 'react'
import React from 'react'

function processTag(tag: string) {
tag = tag.replace(`%%CACHEBUSTER%%`, noUUIDRandom())
Expand All @@ -11,28 +11,8 @@ function processTag(tag: string) {
}
return tag
}
/**
* Execute a script tag in a React component.
* https://macarthur.me/posts/script-tags-in-react/
*/
function BottleData({ src }: { src: string }) {
const elRef = useRef<HTMLDivElement>(null)

useLayoutEffect(() => {
if (!elRef.current) return
const range = document.createRange()
range.selectNode(elRef.current)
const documentFragment = range.createContextualFragment(
`<script src="${processTag(src)}" type="text/javascript"></script>`
)

// Inject the markup, triggering a re-run!
elRef.current.innerHTML = ''
elRef.current.append(documentFragment)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return <div ref={elRef} dangerouslySetInnerHTML={{ __html: src }}></div>
return <img src={processTag(src)} />
}

export default BottleData

0 comments on commit f10c7aa

Please sign in to comment.