DEV Community

Discussion on: Why doesn't useState has a dependency array?

peerreynders profile image
peerreynders • Edited on

In hooks props are often used for state initialization:

const useCounter = (initialCount = 0) => {
   const [count, setCount] = useState(initialCount);
   function increment() {
     setCount(count+1);
   }
   function decrement() {
     setCount(count-1);
   }
   return {count, increment, decrement};
};
Enter fullscreen mode Exit fullscreen mode