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

116
Views
React get component property

Looking for solution to get a property of a React.Compomnent instance, but it seems to be unreadable.

This is my child component:

export default class TabItem extends Component {

    id: string = '';

    getId(): string {
        return this.id;
    }

    constructor(props) {
        super(props);

        this.id = Math.random().toString();
    }

    render() {

        return (
            <>
                {this.props.children}
            </>
        );
    }
};

Parent component:

export default class Tabs extends Component {

    render() {

        return (
            <div>
                <div>
                    {this.props.children && this.props.children.map ? this.props.children.map((child, i) => {
                       console.log(['AAA', child.id, child.getId()]);


                        return (
                            <div className={classname}
                                key={i}
                            >{child.caption}</div>
                        )
                    }) : ''}
                </div>
            </div>
        );
    }
};

I use both like this:

<Tabs>
                                <TabItem
                                    caption={'Booking'}
                                >
                                    AAA
                                </TabItem>

                                <TabItem
                                    caption={'Fitting'}
                                >
                                    BBB
                                </TabItem>
                            </Tabs>

But I get this error:

TypeError: child.getId is not a function

and child.id = undefined.

What am I missing?

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