Skip to content

useCounter medium #Composable Function

By webfansplz @webfansplz

Take the Challenge    简体中文

For this challenge, we're going to implement a counter. 👇:

<script setup lang='ts'>

interface UseCounterOptions {
  min?: number
  max?: number
}

/**
 * Implement the composable function
 * 1. inc (+)
 * 2. dec (-)
 * 3. reset 
 * 4. min & max opotion support
 * Make sure the function works correctly
*/
function useCounter(initialValue = 0, options: UseCounterOptions = {}) {

}

const { count, inc, dec, reset } = useCounter(0, { min: 0, max: 10 })

</script>

Share your Solutions Check out Solutions