The problem is, that I basically the compliant version of the example given in the rule, but the code smell does not go away.
Here is the Code Snippet:
The rule was introduced on Dec 07 2022. Maybe there is bug or something for the validation of this rule?
I am not quite sure, but I would like to get some help.
Though useCallback can be used to avoid renders, it has a side effect, it memoizes results based on the input. Now that may be what you’d want for functions that will receive the same value and you want it computed the same way, but another alternative that also satisfies the rule is
@felixstahmer I do not understand why the issue is raised from the code sample you provided, could you please share the screenshot of the issue from SonarQube and/or share the reproducible code snippet which triggers the issue?
Actually I have to correct myself earlier. I was mistaken that it memoizes the result. Looking more closely at Hooks API Reference – React (reactjs.org) it states it memoizes the callback which means you don’t need to do the useMemo(()=>()=>{...}, [])
We are going to improve the documentation of the rule to better explain non-compliant code and how to fix it. Meanwhile we will remove it from the default profile.