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

143
Visualizações
Keep editable JS Object after React build

Learning React JS, and I am using a Js variable as object inside state

import {DataChara} from './data.js';

This file is like :

const DataChara = {
"Name" : {
   Type : "One",
   Star : 5
},
"Name2" : {
   Type : "Two",
   Star : 5
}
}
module.exports = {DataChara};

And this imported file is used in my state :

state = {Chara : DataChara}

When runing npm build, all files are minified together. I don't want to npm build every time I need to update my JS Object. So I Want to keep this file editable easily.

How can I do It ?

I tried to link this file inside index.html in public, but when compiled again, I've got this message (It's the state) :

Line 14:45:  'DataChara' is not defined  no-undef

Am i doing something wrong ? What is the best way to load external JS file in React, use it in State and still be able to edit this file

EDITED :

Found a Way, don't know if it's the best, but change :

const DataChara

to

window.DataChara

And set my state to :

state = {Chara : window.DataChara}

It's working without error.

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