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

173
Views
Import/Export variable containing Template Literals in React

I am segmenting code and have a array of object containing template literals. When I move the code to separate file and import it i get an error because my template literal isn't defined. If I define it in the export it stays the same when I import it. However, this works fine if the data is contained in the module it self.

How do I do this the correct way?

Export

const name = "temporary"

export const my_questions = [
  {
    id: 0, question: `What is ${name}'s favorite animal?`, alternative: [
      { answers: "Cat", img: "href" },
      { answers: "Dog", img: "href" },
      { answers: "Bird", img: "href" },
    ]
  }
]

export default {
  my_questions
}

Import

import {my_questions} from './data/data_questions'

function App(){

 const TemplateTest = ({name, my_questions}) => {
    return (
      <>
         { my_questions.map(x => <p>{x.question}</p>) }
      </>
    )
  }

   return (
     <div>
        <TemplateTest name="Rusty" my_questions={my_questions}/>
        // What is temporary's favorite animal?
     </div>
   )
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Chris G's answer, solved the problem.

export const my_questions = [
  {
    id: 0, question: name => `What is ${name}'s' favorite  animal?`, alternative: [
      { answers: "Cat", bild: "href" },
      { answers: "Dog", bild: "href" },
      { answers: "Bird", bild: "href" },
    ]
  }
]

export default {
  my_questions
}
about 4 years ago · Juan Pablo Isaza Report
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!