I know how to handle this
inside a function, but in my case none of those solutions works and I still get
this is undefined
The problem is I have a function inside render()
method and I dont know how to handle it.
This is a part of my code
class Pagination extends React.Component {
constructor(props) {
super(props);
this.state = {
//states
}
this.changePage = this.changePage.bind(this);
}
changePage (event) {
// some codes
}
render() {
function PrevPage() {
return (
<li key="p-page" onClick={this.changePage}>
<a href="#"><</a>
</li>
)
}
return (
<div>
<PrevPage />
...
</div>
)
}
}
I get the error at this line
<li key="n-page" onClick={this.changePage}>
I tried putting this line in constructor:
this.PrevPage= this.PrevPage.bind(this);
but PrevPage
is not recognized by this.
Also if i convert PervPage
to arrow function:
PrevPage = () => {
return (
<li key="p-page" onClick={this.changePage}>
<a href="#"><</a>
</li>
)
}
I get this error:
'PrevPage' is not defined no-undef
I know I'm missing somthing but I cant figure out what