useCounter

UseCounterExample

src/prod/numbers/useCounter.ts

import React from 'react';



export const useCounter = (intialState = 0) => {
	const [count, setCount] = React.useState(intialState);

	const incrementCount = () => setCount((x: number) => x+1);
	const decrementCount = () => setCount((x: number) => x-1);
	const resetCount = () => setCount(intialState);

	return [count, incrementCount, decrementCount, resetCount];
};

dist/prod/numbers/useCounter.js

import React from 'react';
export const useCounter = (intialState = 0) => {
    const [count, setCount] = React.useState(intialState);
    const incrementCount = () => setCount((x) => x + 1);
    const decrementCount = () => setCount((x) => x - 1);
    const resetCount = () => setCount(intialState);
    return [count, incrementCount, decrementCount, resetCount];
};

src/prod/numbers/useCounter.ts

import React from 'react';



export const useCounter = (intialState = 0) => {
	const [count, setCount] = React.useState(intialState);

	const incrementCount = () => setCount((x: number) => x+1);
	const decrementCount = () => setCount((x: number) => x-1);
	const resetCount = () => setCount(intialState);

	return [count, incrementCount, decrementCount, resetCount];
};