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

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

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 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