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

128
Views
Can't display data from React Component

Try display props from react component. Need to show Tabs name Do this.

import React from 'react'
import { Link, browserHistory } from 'react-router'

import Tabs from '../../components/Tabs/Tabs'

 function Revenue ({ children }) {
  return (
    <div>
    <div>

              <Tabs items = { ['Home', 'Services', 'About', 'Contact us'] } />
          </div>
      <div className="cont-position">{children}</div>
    </div>

  )
}

export default Revenue

Tabs.js

import React from 'react'
import { Link, browserHistory,IndexLink } from 'react-router'

 function Tabs () {

  var data = this.props.items;
  var newsTemplate;
  newsTemplate = data.map(function(item, index) {
                return (
                    <div key={index}>
                        <li><Link to="/Revenue/IncomeOver" activeClassName="activelink">{item} </Link></li>
                    </div>
                )
            })

export default Tabs

But get error : Uncaught TypeError: Cannot read property 'props' of undefined

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You are using the Stateless Function Components, so instead of using this.props, receive the props in the function arg, try this it will work:

function Tabs (props) {
    var newsTemplate=[], data = props;
    data.items.forEach(function(item, index) {
        newsTemplate.push (
            <div key={index}>
                <li>{item}</li>
            </div>
        )
    });
    return(<div>{newsTemplate}</div>);
} 

check the jsfiddle for working example: https://jsfiddle.net/4o6snef0/

check the article on Stateless Funcion Comp: https://www.reactenlightenment.com/react-state/8.4.html

over 4 years ago · Santiago Trujillo Report

0

It seems like you're trying to write your components as Stateless Functional Components. As the name suggests, your components are written as functions, not as classes. For this reason, you cannot use this.

As such, this is undefined, hence your warning "cannot read property 'props' of undefined".

To access your props, simply add that as the function parameter in your function.

function Tabs (props) {

  var data = props.items;
  var newsTemplate;
  newsTemplate = data.map(function(item, index) {
    return (
      <div key={index}>
        <li><Link to="/Revenue/IncomeOver" activeClassName="activelink">{item} </Link></li>
      </div>
    )
})
over 4 years ago · Santiago Trujillo 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!