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

223
Visualizações
Trying to nest React components

I'm new to React.js and am trying to use it to build myself a website. What I'm trying to do is to nest a child component within a parent component; the parent component should be rendered in the main page with the child component nested inside. I've included an example below of my attempt.

My approach thus far has been to

  1. Create the child component in 'childComponent.js'
  2. Export that child component as 'childComponent'
  3. Import 'childComponent' to parent component
  4. Render 'childComponent' in that parent component
  5. Export that parent component as 'parentComponent'
  6. Import 'parentComponent' to 'index.js'
  7. Render 'parentComponent' in 'index.js'

The problem here is that 'childComponent' is never visible in my React app. Am I taking the wrong approach here? Is there a fundamental mechanic that I'm not understanding?

Thanks in advance!!

--

The child component (childComponent.js):

import React, { Component } from 'react';
import './childComponent.css';

class childComponent extends Component {
  render() {
    return (
      <div className="child-component">
        <span>Hello World</span>
      </div>
    );
  }
}

export default childComponent

childComponent.css:

.child-component {
  width: 100vw;
  height: 300pt;
  background-color: #F4F4F4;
  display: flex block;
  justify-content: center;
  align-items: center;
  align-content: center;
}

The parent component (parentComponent.js):

import React, { Component } from 'react';
import childComponent from './childComponent.js';
import './parentComponent.css';

class parentComponent extends Component {
  render() {
    return (
      <div className="parent-component">
        <childComponent></childComponent>
      </div>
    );
  }
}

export default parentComponent;

The main page (index.js):

import React from 'react';
import ReactDOM from 'react-dom';
import parentComponent from './parentComponent';
import './index.css';

ReactDOM.render(
  <parentComponent/>,
  document.getElementById('root')
);
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Your first, and maybe only, issue is that react components must start with a capital letter.

Capitalized types indicate that the JSX tag is referring to a React component. These tags get compiled into a direct reference to the named variable, so if you use the JSX expression, Foo must be in scope.

From: https://facebook.github.io/react/docs/jsx-in-depth.html#html-tags-vs.-react-components

The comment advising removal of CSS and moving everything into one file is also good advice for debugging and the early stages of a React app.

over 4 years ago · Santiago Trujillo 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