Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ReactJS display return value from component class that extends React.Component

I have a component that I want to show in another site.

components/Hello.js

import React from 'react';

export default class Hello extends React.Component {
  
  render() {
    return (
      <div><p>Hello</p></div>
    )
  };
};

Now I want to import it into my site named "Profile.js".

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

pages/Profile.js

import React from 'react';
import Hello from '../components/Hello';

export default function Profile() {

  return(
    <div>
      {/* Say hello*/}
      {Hello}
    </div>
  );
}

What am I doing wrong? Why wont it say hello on my "Profile.js" page?

>Solution :

React syntax for rendering components is as follow :

export default function Profile() {
  return(
    <div>
      {/* Say hello*/}
      <Hello/>
    </div>
  );
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading