JSFiddle - React, Tailwind, and code Playground

JavaScript

const counter = (def) => {
	let myState = def
  
  return {
  	inc: () => ++myState,
    dec: () => --myState,
    getState: () => myState,
    state: myState
  }
}

const myCounter = counter(10)
myCounter.inc()
myCounter.inc()
console.log(myCounter.getState())
console.log(myCounter.state)