Ad

Failed To Construct 'Comment

- 1 answer

I am new to React. I want to print out an array of objects in the view.

In my render() method of App component, I tried this:

render() {
return (
  <div>
       Your data:
       {
         this.props.val.map(
           (s, i) => 
              <Details key={i} data={s} />
          )
       }
  </div>
);
} 

And In Details Component:

class Details extends Comment{
rendeer(){
return (
  <div>
     <span>{this.props.data.name} {this.props.data.cgpa}</span> 
  </div>
);
}};

Note: Both the components are in the same file. And i am facing this error=>ErroMessage

But if i do this instead of calling details component:

Your data:<br />
       {
         this.props.val.map(
           (s, i) => 
           <p key={i}>{s.name} {s.cgpa}</p> 
          )
       }

It works perfectly fine.

Ad

Answer

You have a typo rendeer(). It should be render().

I think you mistyped Comment, it should be Component. Like :

import React, {Component} from react;

class Details extends Component {
  // ...
}
Ad
source: stackoverflow.com
Ad