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

146
Visualizações
How to return a handlebars template in a React Component?

I'm using handlebars templating on a project, but now I need to use React to handle some logic. I managed to integrate my React component in my non-react project but how do I return a handlebar template in a react component?

const Component = (props) => {
  const { .... } = props;

  // some logic ....

  // return handlebars
  return {{> components/users/user}};
};

I can't convert my handlebars components into React because there are a bunch of them and the logic is implemented in jQuery, so I just need to return the handlebars component in my React component.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

A handlebars template is a string.

JSX is a syntax for generating JS that describes a DOM in terms that aren't based on a string.

If you want to generate a handlebars template, then you need to be working with strings.

const template = "{{> components/users/user}}"

And if you want to return something from the Component then it has to be JSX, so you need to take the string of HTML you generate an insert it into the result.

const compiledTemplate = Handlebars.compile(template);
const html = compiledTemplate({ foo: "Bar" });
const innerHTML = { __html: html };

return <div dangerouslySetInnerHTML={innerHTML} />;

This feels like a remarkably poor idea though. If you want to use React, use React. Convert your handlebars templates to components.

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