2020-11-27 22:32:44 +05:00

22 lines
721 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useState } from "react";
// Если функционал можно где-то переиспользовать или если код логики компонента занимает больше 150 строк, стоит разбить его на кастомные хуки и вынести сюда
/**
* Simple hook
* @param {number} initialState
*/
const useCounter = (initialState = 0) => {
if (typeof initialState !== "number")
throw new Error("Initial counter state must be a number");
const [counter, setCounter] = useState(initialState);
const increaseCounter = () => {
setCounter((prev) => prev + 1);
};
return { counter, increaseCounter };
};
export { useCounter };