Search code examples
javascriptecmascript-6arrow-functions

Getting expected to return a value at the end of the arrow function error


I have a function like this, enter image description here

  const isDisplayStaticAndConditionalSwitcher = (fieldNode, window) => {
    const fieldDataSourceCode = fieldNode.getAttribute('DataSourceCode') || [];
    const nodeValues = Object.values(window?.Designer?.nodes); // get the nodes values 
     
    const formDataSourceCode = nodeValues.map((o) => {
      if (o.displayName === 'Form') { return o.props.code; } 
    }).filter((v) => v)[0];

    return fieldDataSourceCode === formDataSourceCode;
  };

I am getting the error, expected to return a value at the end of the arrow function error How should I resolve the issue?


Solution

  • Your lint rules want you to explicitly return undefined:

    nodeValues.map((o) => {
      if (o.displayName === "Form") {
        return o.props.code;
      } else {
        return undefined;
      }
    });