I know in vanilla ES6 you can write a class that extends a functional class. This is explained here.
React supports both ES6 class components, via extending React.Component, and functional components. I'm getting the following error when attempting to extend a functional component, though.
TypeError: Cannot call a class as a function
I'm trying to write some code that extends a component and works for both ES6 class components and functional components. I want to write a function that returns a component, but instead of a higher order component I just want to extend and modify some props.
Below is some example code that I've tried and does not work. Is this possible? I realize the BarExtended would not render Bar at all, but I was just testing. Unless this is part of the issue.
function Bar() {
return (
<h1>Bar</h1>
);
}
class BarExtended extends Bar {
render() {
return (
<h1>BarExtended</h1>
);
}
}
ReactDOM.render(
<div>
<BarExtended />
</div>,
document.getElementById("foo")
);