3

I'm using react-highcharts in my project. I want to generat chart-component dynamicaly and change their number according to user's choice. I wrote component and function which gets data and makes array of highcharts component and returns them:

export default class ContentChartItem extends Component {

    constructor(props) {
        super(props);
        this.state = {
        }

        this.config = {}

    render() {
        let { process_data } = this.props;
        let config = this.config;

        return (
            <div className="column">
                {typeof process_data == "undefined" ? " "
                    :
                    <div className="ui segment">
                        {this.getChartItemsList}
                        <div className="ui button tiny fluid sidenav4">
                            Info
                        </div>
                    </div>
                }
            </div>
        )
    }

    getChartItemsList = () => {
        let config = this.config;
        let { process_data } = this.props;
        let chartContainers = [];
        for ( let i=0; i<process_data.length; i++ ) {
            chartContainers.push( <ReactHighcharts config = {config}> </ReactHighcharts> )
        }

        return chartContainers;
    };


}

During render I get mistake:

Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.

What can be a reason? And how can I solve it.

Vikas Yadav
  • 3,094
  • 2
  • 20
  • 21
Sam Fisher
  • 746
  • 2
  • 10
  • 27
  • 4
    because you forgot `()` here: `{this.getChartItemsList()}`, call that method, voted to close the ques : 'Simple Typo'. – Mayank Shukla Dec 28 '17 at 11:02

1 Answers1

1

You forgot to call this.getChartItemsList():

{typeof process_data == "undefined" ? " "
                    :
                    <div className="ui segment">
                        {this.getChartItemsList()}
                        <div className="ui button tiny fluid sidenav4">
                            Info
                        </div>
                    </div>
                }

By the way you can do the condition with this syntax:

{
  process_data && (
  <div className="ui segment">
    {this.getChartItemsList()}
    <div className="ui button tiny fluid sidenav4">
      Info
    </div>
  </div>
)}
Sagiv b.g
  • 30,379
  • 9
  • 68
  • 99