I have a header.tsx file with:
import React from "react";
export const Header = (title:any) => {
return (
<div>
<h1>{title}</h1>
</div>
)
};
Then my index.tsx contains:
import React from "react";
import ReactDOM from "react-dom";
import { Header } from "./header"
ReactDOM.render(<Header title={"abc"} />, document.getElementById("root"));
However, when I do npm run dev, the code will compile successfully, the localhost page is empty (blank). Instead I expected it to display "abc".
If I instead define Header in this fashion, it'll magically work:
export class Header extends React.Component<{ title: string }> {
render() {
return (
<div>
{this.props.title}
</div>
)
}
};
So what's wrong with the way that Header was originally defined above?