Skip to content

Instantly share code, notes, and snippets.

@rahulmore01
Created September 22, 2023 10:22
Show Gist options
  • Save rahulmore01/ae08b467bb3d07e942e9602cb831a08b to your computer and use it in GitHub Desktop.
Save rahulmore01/ae08b467bb3d07e942e9602cb831a08b to your computer and use it in GitHub Desktop.
blog-counter
import { useState } from 'react';
function useCounter(initialValue = 0) {
const [count, setCount] = useState(initialValue);
const increment = () => {
setCount(count + 1);
};
const decrement = () => {
setCount(count - 1);
};
return {
count,
increment,
decrement,
};
}
export default useCounter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment