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

115
Visualizações
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 à 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