Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda