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

104
Vistas
Set Prop Key Dynamically JSX

I'm wondering if it's possible to do the following in JSX (this code does not work, just an example of what I'm trying to do):

const propKey = 'someProp';
const jsx = <MyComponent [propKey]="some value" />;
// evaluates to <MyComponent someProp="some value">

I'm using babel es2015 stage-1, so I could spread a dictionary like this:

const extraProps = {[propKey]: 'some value'};
const jsx = <MyComponent {...extraProps} />

but that seems too clunky for just one prop. I'm not looking to use React.createElement; all my classes are es6 classes. Thanks!

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can create in the JSX an object using the computed property names, and spread it:

const propKey = 'someProp';
const jsx = <MyComponent { ...{ [propKey]: "some value" } } />;
over 4 years ago · Santiago Trujillo Denunciar

0

JSX is syntactic sugar for calling React.createElement. So one solution is to call React.createElement directly:

const element = React.createElement(MyComponent, {[propKey]: 'some value'});
over 4 years ago · Santiago Trujillo 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