Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
using SVGs with scripts in react.js

I have an svg that contains a script tag that is interactive and reacts to key presses. I am unable so far to get the svg to work in react.js.

I am able to display the svg statically using an img element:

<img src={*svg code*} alt="svg title" width="400px"/>

doing it this way however doesn't run the script element in the svg and thus it is not interactive. I also tried using the svgr package, and followed the website guide exactly:

npm install --save-dev @svgr/core

import { transform } from '@svgr/core'

const jsCode = await transform(
  svgCode,
  { icon: true },
  { componentName: 'MyComponent' },
) 

when I change variable names and run this I get errors like:

./node_modules/@ampproject/remapping/dist/remapping.mjs Can't import the named export 'TraceMap' from non EcmaScript module (only default export is available)

and a bunch of other errors but with "TraceMap" replaced with something else

side note: in my element in my svg, I have

type="text/javascript"

since the errors say 'from non EcmaScript...' I changed it to

type="application/ecmascript"

I get the same errors either way.

Im not sure what the difference is, its just the two versions I am aware of.

Anybody know what Im doing wrong? I believe the svgr is the solution somehow, but not the way im doing it.

Any ideas?

Thanks!!!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda