I'm trying to return a function component after the condition is checked within a class component. Here is my code:
class Page extends React.Component {
constructor(props) {
super(props);
this.state = props.warn;
}
function WarningBanner() {
if (this.state == false) {
return null;
}
return (
<div className="warning">
Warning!
</div>
);
}
render() {
return (
<div>
<WarningBanner />
</div>
);
}
}
ReactDOM.render(
<Page warn={true}/>,
document.getElementById('root')
);
Is a function component inside a class component considered a valid component ? Or is there a another way to define a function component inside a class component?
What is the difference between a function component inside class component or a function component outside a class component ?
I have also tried doing this:
<WarningBanner warn = {this.state}/>
And
function WarningBanner(warning) {
if (warning.warn == false) {
return null;
}
return (<div className="warning">Warning!</div>);
}