How to reduce Cognitive Complexity in a Input field and if condition in reactjs

26 Views Asked by At

I have a function and if statement as below. How I can lower the cognitive complexity?

const renderInput = (element, a) => {
return (
<Input
  key={a}
  name={element.label ? element.label : ''}// Cognitive Complexity 
  type={element.type ? element.type : ''}// Cognitive Complexity 
  label={element.label ? element.label : ''}// Cognitive Complexity 
/>
)
}

const renderTag = (element, a) => {
if (element.element === 'input' ) {             // Cognitive Complexity 
   if (element.type === 'submit' ) {       // Cognitive Complexity 
     return testFunction1()
   }
   if (element.type !== 'file') {         // Cognitive Complexity 
     return testFunction2()
   }
}
}
0

There are 0 best solutions below