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

171
Visualizações
Using Javascript to create html custom Tag

class Headers extends React.Component {
  render() {
    const selected = this.props.selectedPane;
    const headers = this.props.panes.map((pane, index) => {
      const title = pane.title;
      const klass = index === selected ? 'active' : '';

      return (
        <li
          key={index}
          className={klass}
          onClick={() => this.props.onTabChosen(index)}>
          {title}{' '}
        </li>
      );
    });
    
    return (
      <ul className='tab-header'>
        {headers}
      </ul>

    );
 }
}

export default class Tabs extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      selectedPane: 0
    };
    this.selectTab = this.selectTab.bind(this);
  }

  selectTab(num) {
    this.setState({selectedPane: num});
  }

  render() {
    const pane = this.props.panes[this.state.selectedPane];

    return (
      <div>
        <h1>Tabs</h1>
        <div className='tabs'>
        <Headers
            selectedPane={this.state.selectedPane}
            //onTabChosen={this.selectTab}
            panes={this.props.panes}>
          </Headers>
          <div className='tab-content'>
            <article>
                hellooooo
              {pane.content}
            </article>
          </div>
        </div>
      </div>
    );
  }
} 

I'm currently creating a 3 tab section where if you click on a tab, it gives you a new pane.

When looking at the render function I see a custom tag called Headers.

I know it coming from the Headers class at the beginning, but how does that format work? Is that a custom tag we building?

Also when looking at its properties such as onTabChosen, when it is deleted in the render method (for learning purposes) and I click on a selected tab, an error comes up saying

"_this.props.onTabChosen is not a function".

this.props.onTabChosen(index).. was written in the Headers class but not as a function correct?

I guess because I am also confused on how this.props.onTabChosen(index) works since onTabChosen was never declared anywhere, just input after props.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When looking at the render function I see a custom tag called "Headers".

That is not a custom tag. That is a React Component.

I know it coming from the Headers class at the beginning, but how does that format work?

Headers is either a function or a class (i.e. a constructor function).

The function will be called and the first argument passed to it will be an object with properties and values that match the props on the JSX element.


If you're going to use React then read a tutorial, this is very introductory level stuff for the framework.

It is covered very early on in both the MDN tutorial and the official React tutorial.

I guess because I am also confused on how this.props.onTabChosen(index) works since onTabChosen was never declared anywhere, just input after props.

It was declared, just not in the piece of code you shared.

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