Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign uphandleTabsScroll uses useCallback without passing arguments #20442
Comments
|
Good catch. I wonder why the linter doesn't complain. material-ui/packages/material-ui/src/Tabs/Tabs.js Lines 333 to 337 in 5a794bd
This is intended. |
|
So the solution would be? diff --git a/packages/material-ui/src/Tabs/Tabs.js b/packages/material-ui/src/Tabs/Tabs.js
index b59620fb1..97b0021e4 100644
--- a/packages/material-ui/src/Tabs/Tabs.js
+++ b/packages/material-ui/src/Tabs/Tabs.js
@@ -334,6 +334,7 @@ const Tabs = React.forwardRef(function Tabs(props, ref) {
debounce(() => {
updateScrollButtonState();
}),
+ [],
);
React.useEffect(() => {@cubbie How did you spot it? |
|
I had that warning pop up from Preact. Probably should remove useCallback, because it makes no sense to use this method with an empty array, it will create an additional wrapper which wont increase performance (at least I think? I could be wrong) |
|
@cubbie Awesome to see the library used with Preact :D. I wish React had such warning, how comes they don't Regarding the best option, removing vs keeping. I honestly don't know. Either way sounds great. @eps1lon What's your preference? |
|
I think in this instance it will have to be kept because |
But in 99.9% of the cases you'll use the second argument anyway. That should be the default. There are use cases to omit them for useMemo/useCallback but in those cases you're on your own and should disable the rule. |
|
I actually can't think of the 0.01% that you'd not want a dependency array when using |
Current Behavior😯
also calling useEffect on line 349 of Tabs.js with no second argument as well.
Expected Behavior🤔
Pass an additional second argument or remove the useCallback method as it creates an unnecessary wrapper.
Steps to Reproduce🕹
Steps:
n/a
Context🔦
Remove error messages.
Your Environment🌎