counter.ts 274 B

123456789
  1. export function setupCounter(element: HTMLButtonElement) {
  2. let counter = 0
  3. const setCounter = (count: number) => {
  4. counter = count
  5. element.innerHTML = `count is ${counter}`
  6. }
  7. element.addEventListener('click', () => setCounter(counter + 1))
  8. setCounter(0)
  9. }