You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const FancyButton = React.forwardRef((props, ref) => {
const handleSomething = () => {
if (something) {
do something
}
}
const handleSomethingElse = () => {
if (somethingElse) {
do somethingElse
}
}
if (condition) {
return sth
}
if (condition2) {
return sth2
}
if (condition3) {
return sth3
}
if (condition4) {
return sth4
}
return (
<button ref= { ref } className = "FancyButton" >
{ props.children }
< /button>
);
});
Currently, cognitive complexity of such component would be 15, while the equivalent component using class syntax and regular functional syntax will have only one. We should avoid adding complexity of nested functions to the outer function in such case.
The text was updated successfully, but these errors were encountered:
consider React forwardRef component such as
Currently, cognitive complexity of such component would be 15, while the equivalent component using class syntax and regular functional syntax will have only one. We should avoid adding complexity of nested functions to the outer function in such case.
The text was updated successfully, but these errors were encountered: