I'm trying to change the value of let showtext to change the text that is displayed.
When I change the value of showtext in code the text changes, but the variable doesn't change when I click the button.
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable no-eval */
import * as React from "react";
import "../../../styles/colour_sdgs.css";
import "../../../styles/infotext.css";
import Logo from "../../../SDGLogos/Goal-06.png";
let showtext = 1;
const sdg = "sdg06";
const text = {
1: `text1`,
2: `text2`,
};
function incrementCount(): void {
showtext++;
}
function decrementCount(): void {
showtext--;
}
export const sdg06infotext = (): JSX.Element => {
return (
<div>
<div className={`colour_${sdg}`}>
<div className="header">
Hochwertige Bildung <img className="sdglogo" alt="logo" src={Logo} />
</div>
</div>
<div className="infotextbox">
<p> {text[showtext]} </p>
<p>blabla</p>
<p>
other text
</p>
</div>
<button type="button" onClick={incrementCount}>
{showtext}+
</button>
<button type="button" onClick={decrementCount}>
{showtext}-
</button>
</div>
);
};