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

172
Vistas
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 Respuestas
Responde la pregunta

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 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