Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!