I'm trying to build a class that's somehow modelled to how React classes are made. This is what I have so far:
export default class Pagination {
constructor(attr) {
const { totalPages } = attr;
this.totalPages = totalPages;
this.activePage = 1;
}
goToPage(newPageNumber) {
console.log(newPageNumber);
}
render() {
const pages = [];
for (let i = 1; i <= this.totalPages; i++) {
pages.push(`
<li>
<a href="javascript:void(0)" onclick="this.goToPage(${i})" class="${
i === this.activePage ? 'active' : ''
}">${i}</a>
</li>
`);
}
return pages.join('');
}
}
The problem is, when I click a link, it says this.goToPage is not a function. How do I properly assign my class' method goToPage to the <a> tag?