Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!