From 1584d5a750e588625e197d2ac47bd687b5c29b86 Mon Sep 17 00:00:00 2001 From: Chris Wilton-Magras Date: Thu, 14 Mar 2024 10:48:32 +0000 Subject: [PATCH] Do not call decrement func when button disabled --- src/App.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/App.tsx b/src/App.tsx index 8e548e9..c1fcc24 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,7 +6,9 @@ function App() { const downIsDisabled = count <= 0; const increment = () => setCount((prev) => prev + 1); - const decrement = () => setCount((prev) => Math.max(prev - 1, 0)); + const decrement = () => { + !downIsDisabled && setCount((prev) => Math.max(prev - 1, 0)); + }; return (