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

Why It Isn't Displaying (React Small App)

I cannot figure out why the text isn’t displaying? The header class should be exporting the render function which should have the header in it.

App.js:

    import logo from './logo.svg';
import './App.css';
import header from './Components/header';


function App() {
  return (
    <header />
  );
}

export default App;

header.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

    import React, { Component } from 'react';

export class header extends Component {
  render() {
    return ( 
    <div> <h1> dfdfd </h1></div>
        );
  }
}

export default header;

>Solution :

try to use Uppercase for the function ‘header’

import Header from "./Components/header";

function App() {
  return <Header />;
}

export default App;


note: filename lowercase is okay.

EDIT:

More details example:

App.js

import { header as Header } from "./Components/header";

function App() {
  return <Header />;
}

export default App;

header.js

import React, { Component } from "react";

class header extends Component {
  render() {
    return (
      <div>
        {" "}
        <h1> dfdfd </h1>
      </div>
    );
  }
}

// export default header; // No Problem if you 'import Header from "/path/to/file"'
export { header }; // Must be 'import {header: Header} from "/path/to/file"'

but I suggest to always write your component class / function name start with uppercase.

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