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

121
Vistas
Import react component and add to dom automatically

I am trying to run my jsx within a javascript file like this:

import React from 'react'

export class HeaderNav extends React.Component {
  constructor(props) {
    super(props)
    console.log('Created Component')
  }
}

console.log('Create New Component');
<HeaderNav />

I then have an mdx file that imports the react component like this:

import '../mdx/header-nav'

This doesn't create the component and only Create New Component is output to the console, and I would expect both console.logs to print.


When I import the component into my MDX file, and place the html then it works just fine:

import React from 'react'

export class HeaderNav extends React.Component {
  constructor(props) {
    super(props)
    console.log('Created Component')
  }
}

I then have an mdx file that imports the react component like this:

import { HeaderNav } from '../mdx'

<HeaderNav />

This creates the component and outputs Created Component in the console.


Is there something that I need to do to use the first method of importing the file so I don't have to place the element in all of my mdx files?

about 4 years ago · Juan Pablo Isaza
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