I have a situation where I want to render a different header depending on the value of a variable in a Redux State.
This is my MyClass.js
class MyClass extends React.Component {
constructor(props) {
this.state = {
headerState: "home"
};
this.GetHeader = this.GetHeader.bind(this);
}
GetHeader() {
const headerType = this.renderHeader;
if (headerType == "a") {
return (Some html code);
} [...] {
return (Some html code);
} else {
return (Some html code);
}
}
render() { <
GetHeader / > // This is line 79
}
function mapStateToProps(state, ownProps) {
return {
renderHeader: state.renderHeader
};
}
}
export default withRouter(connect(mapStateToProps)(MyClass));
This is my reducer:
export default function renderHeaderReducer(state = [], action) {
switch(action.type) {
case 'RENDER_HEADER':
return [...state, Object.assign({}, action.headerType)];
default:
return state;
}
}
When I tried running the code, on the browser it says:
Uncaught ReferenceError: GetHeader is not defined at Header.render (Header.js:79).
I followed this doc(first example)
Not sure what I am doing wrong or what concepts I must have misunderstood in terms of binding methods to this context. Cheers.