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

174
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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